Am trying save more than one record so I am using for loop in server action but I am facing some issue while running this server action, data is not getting saved can anyone tell me how to implement this
Hi Annish,
Please make sure the following:
If these aspects are configured correctly, the loop should create multiple items in your entity as required.
I can't see an obvious reason why this would go wrong, other than that there's a timeout causing a rollback of the database transaction. Have you debugged it?
Hi, I have debugged it I noticed that only the first record is getting saved / updated other record is not getting updated
this is from database before running the server action
I have changed the value and run my server action
this is from database after updating
But does the for each run more than once? Is there actually more than one record?
If so, have you checked what the Id of the record is? Is it NullIdentifier() or does it have a value? Are they different values?
Debugging is more than just noticing something goes wrong. It's trying to find why things go wrong.
Are you passing list of Ids to the input parameter used in for each loop?
Because when only one record gets saved it is usually because it gets only One current Id and not the list of Ids.
And If you are passing the List Of Ids and still getting issue, then can you please share the oml..
Regards
Hi I have created another application with different entity and aggregate still facing the same issue, only the first record is getting saved I have attached the oml file for reference
You're looping through In2 variable which is a list. All good with that.
But inside the loop, you're calling CreateOrUpdateEmployee and passing In1 variable which is a variable of type Employee. It will always have same value.
Solution:
The problem is same as I pointed out in my previous comment. You can refer back to 2nd bulleted point there.
Thank you it worked
Please make sure you understand what went wrong, and how you can detect it the next time something like this happens. If you understand how a For Each works, and what the input to the save action should be, you would've caught this bug when debugging.
I have updated the Oml. Please Refer to it.
You were passing different inputs to the loop and create action.
Regards,
Aditya