Calling sn_sc.CartJS().orderNow() in Run Script activity of a workflow is causing an infinite loop and as a result many RITMs will be created until you cancel the transaction


Description

Calling sn_sc.CartJS().orderNow() in Run Script activity of a workflow is causing an infinite loop and as a result many RITMs will be created until you cancel the transaction.

Steps to Reproduce

1. Create a catalog item "child item" which does not contain any variable and does not have any associated workflow/flow as well.

2. Create a workflow which only contains a Run Script activity with the following script:

var cart = new sn_sc.CartJS();
cart.setRequestedFor('a8f98bb0eb32010045e1a5115206fe3a');
var item = {
'sysparm_id': '76af12c21bb42810c74543f28d4bcbfd',
'sysparm_quantity': '1',
'variables': {}
};
var cartDetails = cart.orderNow(item);
workflow.info(JSON.stringify(cartDetails));

NOTE: The sys_id "a8f98bb0eb32010045e1a5115206fe3a" used for cart.setRequestedFor() is the sys_id of the demo user Abraham Lincoln in OOB instance. The sys_id "76af12c21bb42810c74543f28d4bcbfd" specified for 'sysparm_id' in the JSON "item" is the sys_id of a custom catalog item (You should replace this sys_id with the one for the catalog item you have created at step 1).

3. Create another catalog item "parent item" and associate the workflow created at step 2 to this catalog item.

4. Submit the catalog item "parent item".

5. Notice that it takes long time to submit the catalog item. Please make sure to run "cancel_my_transaction.do" after it is running for a while to cancel the transaction.

6. Go to the table sc_req_item and notice that there are many RITMs for the catalog item "child item" get created.

7. Modify the workflow by adding a Timer between the Begin activity and the Run Script activity.

8. Submit the catalog item "parent item" again.

9. Notice that submission of the catalog item is completed very quickly and there is only 1 RITM for the catalog item "child item" get created.

Workaround


You can add a Timer before the Run Script activity. There should be only 1 RITM get created by this workaround.


Related Problem: PRB1456140