Issue related with a!writeToDataStoreEntity() function in interface level

Hi,

I have 2 forms in my application and I'm using one CDT for both the forms. I've used a!writeToDataStoreEntity() function  in submit button for storing the data. Once If I click on the submit button one row is inserting into the database.For the second form, If I click on the submit button a separate row is inserting instead of updating within the same row, the same issue is persisting with the other forms also.

Can you please suggest me to resolve this issue.

 

 

Even If I remove the a!writeToDataStoreEntity() function on second form and write the data using smart service then also new row is inserting. Its not updating with the existing row.

Thank you in advance!

 

 

Thanks,

Dharma

  Discussion posts and replies are publicly visible

  • Hi Dharma, Once the data is written in DB, on click to the first submit button, you will have to save the fv!storedValues of function a!writetodatastoreentity to the variable, so that the primary key value in db will be updated in the variable. onsuccess parameter of a!writetodatastoreentity function allows you can save the fv!storedvalues to the variable which you are using to update the data. hope this helps.
  • Hi Dharma,
    if their is primary key value in cdt then it will update,else i will insert new record.
    so,in your second form while you are getting data make sure that cdt has primary key value.
    use fv!storedValues in a!writetodatastoreentity() in your first form.

  • Hi Dharma Rao (dharmaraok) ,

    By reading your description, there may be one of the following issue

    1) There a field in CDT which is declared as primary key (auto generate).
    i) The data is inserted into db first time and primary key id X is generated.
    ii) Trying to insert data second time without setting the primary key field value to X.
    Solution: Pass the CDT with primary key field set to X to second a!writeToDataStoreEntity() function

    2) There is no primary key field in CDT
    Solution: Add/make a field in CDT as primary key. Insert your data to db using first a!writeToDataStoreEntity() function, primary key id X is generated. While executing the a!writeToDataStoreEntity() function second time, set the primary key field value of CDT to X.
  • Hi Dharma,

    it seems in your second form you are not using the primary key value. If you want to update the existing record in from the second form then provide the primary key value in the CDT while using a!writetostatstoreEntity() otherwise every time it will create a new record.

    Regards
    Abhay Giri
  • Hi Dharma, simple funda is if primary key is null then it is insert else update. So populate the primary key value in CDT while inserting second form for update.