Insert or Update using xtk.session.Write | Community
Skip to main content
Level 3
December 22, 2022
Question

Insert or Update using xtk.session.Write

  • December 22, 2022
  • 2 replies
  • 3629 views

Hi,

Can anyone please confirm if the below approach is correct if we want to insert or update the data in a table using JS?

 

insertUpdateQuery = <order _key="@custId,@productName,@subProductName" _operation="insertOrUpdate"  xtkschema = "cus:order"
productName = { productName }
subProductName = { subProductName }
custId = { custId }
productid= { productid}
datetime = { datetime }
/>
xtk.session.Write(insertUpdateQuery);

 

We are getting duplicate key value violates unique constraint errors in logs as during insertion or updation we can get data that might be already present based on the 3 key fields.

Based on my understanding if we use insertorUpdate operation it should not give a duplicate error. Can anyone please with this?

Version is V8

Thanks 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

2 replies

Shubham_Goyal__
Level 6
December 23, 2022

Hi @ratika ,

 

Your write function and understanding related to "insertOrUpdate" operation are correct, as if there is a value that exists post the reconciliation of _key then the "insertOrUpdate" will update that record else it will insert.

Did you try to run the same js function in any other workflow to check if there are any caching/corruption issues in the current wkf?

Also, did you try to use _operation="update" (for testing) to observe if this also returns the same error of duplicate key?

 

Br,

Shubham

 

Sukrity_Wadhwa
Community Manager
Community Manager
January 12, 2023

Hi @ratika,

Were you able to resolve this query or do you still need more help here? Do let us know.

Thanks

Sukrity Wadhwa