Currently facing an issue where I need to retrieve the auto-incremented field value of the last inserted row without passing it during insertion, as it is generated automatically. In order to achieve this, I first add data to the table and then call a method to fetch all the data from that table. Without using a callback function, I am unable to obtain the data of the current row.
blockBusinessPartnerItem(): void {
this.isBusinessPartnerSelected = false;
this.logger.debug('Currently inside the blockBusinessPartnerItem method');
const businessPartnerItem = {
BlockKey: 0,
BpKey: this.businessPartnerId,
ItemKey: Number(this.itemKey)
};
this.adminService.addBusinessPartnerItemBlock(businessPartnerItem).subscribe(response => {
this.toasterService.popAsync('success', 'Successfully Added Business Partner Item');
}, error => {
const message = 'Unable to submit business partner item';
this.toasterService.popAsync('error', message);
}, () => {
this.adminService.getBusinessPartnerItemBlock().subscribe((data) => {
const arrSize = data.length;
const siz = arrSize - 1;
const row = data[arrSize - 1] ;
this.logger.debug('current block key :' + this.currentBlockKey);
this.params.api.addItems([{blockKey: data[arrSize - 1].BlockKey , bpKey: this.businessPartnerId ,
bpName: this.businessPartnerName, itemKey: this.itemKey}]);
});
// this.businessPartnerId = 0;
// this.itemKey = '';
}
);
}
However, a problem arises when debugging as the blockKey appears undefined.
this.params.api.addItems([{blockKey: data[arrSize - 1].BlockKey , bpKey: this.businessPartnerId ,
bpName: this.businessPartnerName, itemKey: this.itemKey}]);