Getting the auto-incremented field value of the current record after insertion in Angular2+ ASP.net can be achieved by utilizing

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}]);

Answer №1

The reason behind your problem lies in the fact that you are referencing data[arrSize - 1].BlockKey rather than data[arrSize - 1].blockKey. Pay attention to the difference in letter case (b versus B).

It is important to remember that JavaScript is a case-sensitive language. BlockKey and blockKey represent different variables, with BlockKey not being present in your return data while blockKey is.

To gain more insight on this topic, feel free to check out the following article:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can you make an IonPopover dynamically appear from a button with the perfect positioning?

I want to display a popover below a button when the button is clicked, similar to the example on the Ion docs page. However, I am having trouble implementing this in React as the code provided is only for Angular. Here is my current code: ... <IonButt ...

Issue with JavaScript cookie not being recognized in server-side code

When I try to access Response.Cookies["alertsCookie"], it returns an empty cookie. To solve this issue, I decided to create two cookies as a workaround. I couldn't figure out how to read a cookie in a specific path, so I stored them in both the page ...

The identification of the field is not being transmitted by ng-select

Looking for help with Angular! I have an ng-select box where I can choose countries, and it's working fine when I select an option and submit - it submits the id as expected. However, when pre-populating the ng-select with data and submitting, it&apos ...

Utilizing AngularJS2 with PHP on Apache server

Starting my journey with AngularJS today. Following tutorials on AngularJS version 2 using JavaScript. Node.js is a requirement, but my current development environment includes PHP, MySQL, and Apache (Xampp). I am curious if it is possible to develop and ...

Is there a way to integrate TypeScript with styled components to display suggested properties on the component?

Hey there fellow developers! I'm currently diving into the world of TypeScript and trying to get the hang of it. One thing that's bothering me is not being able to see recommended props on a styled component while using TypeScript. For instance ...

Ways to determine the present condition (Checked or Unchecked) of Angular Material Multiselect

When working with MatSelect and allowing multiple selections of items, I am seeking a way to determine the current state of an item. Specifically, I want to know if the currently clicked item is checked or unchecked, as this will determine whether or not ...

Snapshots testing app Expo TypeScript Tabs App.tsx

After setting up an Expo project with Typescript and Tabs, I decided to add unit testing using Jest but ran into some issues. If you want to create a similar setup, check out the instructions here: . Make sure to choose the Typescript with Tabs option whe ...

Understanding TypeScript - Changing immutability and reversing Readonly<T>

Let's consider a scenario where I have the following mutable class: class Foo { constructor(public bar: any) { } } I am able to create instances of this class with readonly properties like this: const foo: Readonly<Foo> = new Foo(123); fo ...

Creating a Mat Table in Angular 7 by Mapping an Object with an Array of Objects

I've been working on mapping one of my objects to a mat-table. The input object from the Web API looks like this: [ { "inventoryId": 1004, "inventoryName": "Red Shirt Material", "dateReport": [ { ...

Is it possible to access a user account in asp.net without utilizing identity authentication?

As a newcomer to ASP.NET, I'm in the early stages of learning about it. The online tutorials I've been following indicate that using identity is necessary for logging into ASP.NET. I'm curious if there are alternative methods for logging in ...

What is the best way to integrate a jQuery Plugin into an Angular 5 application powered by TypeScript 2.8.1

I am trying to incorporate jQuery into my Angular 5 project using TypeScript 2.8.1. I attempted to follow Ervin Llojku's solution but it didn't work: First, install jquery via npm npm install --save jquery Next, install the jquery types npm i ...

Tips for displaying dynamic data using innerHTML

Recently, I set out to implement an infinite scroll feature in Angular 2 using JavaScript code (even though it may seem a bit unusual to use JavaScript for this purpose, it's actually working perfectly). Initially, I was able to create an infinitely s ...

Parent observable method encountering an error while grouping multiple HTTP calls in Angular

I am facing an issue with managing multiple http calls and handling errors that may occur during their execution. I want to be able to identify which calls have failed so that I can retry them using a different method. However, without visibility at the co ...

Learn how to use an Angular Directive to automatically set the default value within an HTML Text box element. The code snippet provided below will guide you

I have encountered an issue with the code below. It seems to be working fine for changing the innerHTML of div and heading tags, but I am facing difficulties when trying to apply it to textboxes. @Component({ selector: 'app-root', template: ...

Is there a way to implement hover behavior for a Material-UI Button within a ButtonGroup component?

When using MUI v5, I am encountering an issue where the first button in the code provided is only half working. The button is initially colored red (both the border and text), however, upon hovering over it, the color of the border changes to blue. This is ...

Unable to access the FormControl instance directly. It is not possible to read the property 'invalid' of an undefined value

Accessing in Angular docs is not the same as before, you must first grab the FormGroup instance and then find the FormControl instance within it. I wonder why? This example works: <form [formGroup]="myForm" (ngSubmit)="onSubmit()"> <div class=" ...

The NgModule recognition system does not detect my library module

My AccordionModule within my Angular 2 library initially encountered a problem of not being recognized as an NgModule during the first compilation by angular-cli. However, it automatically reloaded after the error and was then successfully compiled with th ...

Displaying search results in various Angular components

On my home page (homePageComponent), I have a search feature. When the user clicks on the search button, they are redirected to a different page called the search list page (searchListComponent). Within the searchListComponent, there is another component c ...

Is it IIS or the application causing the sluggish performance?

The team has an Android application with a .NET C# backend hosted on IIS, but they have recently noticed unexpected latency issues affecting customers. The issue occurs when users are unable to change the channel or log out of the live media streaming app ...

Issue with Ionic 4 IOS deeplinks: Instead of opening in the app, they redirect to the browser

After working diligently to establish deeplinks for my Ionic 4 iOS application, I meticulously followed a series of steps to achieve this goal: I uploaded an Apple site association file to the web version of the app, ensuring the utilization of the prec ...