Question
Sytel Reply
IT
Last activity: 27 Apr 2022 0:42 EDT
Use of Save inside a loop with an external Commit
Hi, I'd like to discuss about the best practice about the use of the activity of Save inside a loop, that has an external commit. The point is that using this, all the deferred action are undermined by the save activity. In this way the commit will execute only the last deferred action. Example: I've got an activity that has a loop within the element of a data type, and using the information of the data type, I've to create a child case, and then delete the element from the data type. So my activity was structured like this pseudo-code:
Hi, I'd like to discuss about the best practice about the use of the activity of Save inside a loop, that has an external commit. The point is that using this, all the deferred action are undermined by the save activity. In this way the commit will execute only the last deferred action. Example: I've got an activity that has a loop within the element of a data type, and using the information of the data type, I've to create a child case, and then delete the element from the data type. So my activity was structured like this pseudo-code:
For each element D in DataType
call createWorkPage
call AddCoveredWork
call Save
Obj-Delete-By-Handle
Commit
In this way I expected that all the cases were created, and the element inside the data type were canceled, once the commit was executed. The reality is that not all the element were deleted, but only the last was erased from data type. Opening an SR, it was pointed me, that the Save undermines the deferred action, due its internal commit. I've explained all this because I've a question: what is the best practice to do this? One suggestion can be: instead of Save activity, use Obj-Save. This will raise a severe exception the lower our score. Another suggestion is to move the commit inside the loop. This can work, but when the number of the loop become higher and higher I suppose this can have effect on the performance. By the way this is what we've done as workaround. I don't see other way. So I'm asking you: can you suggest me a best practice to do this? Thanks for your help, Daniele