Create child RITMs from workflow-task (sn_sc.CartJS) is looping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 08:19 AM
Dear community,
I have a workflow task as part of a workflow/RITM which creates another RITM as "child" RITM.
I use sn_sc.CartJS and handover some variables for the new child-> this works perfect.
But now I have the need to loop over an array (e.g.: 3 items in it) and dependent on the array.length
I have to start several child RITM with sn_sc.CartJS where the variables then differ a bit.
The issue now is, that putting such a sn_sc.CartJS into a for loop, this ends in an endless loop and the system creates a new RITM every 2 sec.
Do you have another idea/approach how to implement this?
Many thanks
Best regards
Eckhard
P.S. I am on vancouver (Build tag: glide-vancouver-07-06-2023__patch6-01-11-2024)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 08:39 AM
Share the script...
☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 08:41 AM
Hi @Eckhard ,
ServiceNow provided workaround for this. Please refer to the below thread.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0869002
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-22-2024 11:08 AM - edited 02-22-2024 11:13 AM
Dear both,
the KB article is more or less my situation - thanks. The proposed solution (setting a timer before sn_sc.CartJS) is not clear to me. Does it mean a timer in the workflow to wait e.g.: 5 sec to reach the wf-step including the script?
Or is it a timer in my for...loop, which would be strange because a real "sleep" function is for my understanding not recommended (gs.sleep) in server side scripts.
Thanks
best regards
Eckhard
See here my function which is part of a central script include, that I call from the wf-task:
createOrder: function (cat_item, requested_for, variables, quantity) {
if (!quantity) {
quantity = "1";
}
var grCatItem = new GlideRecord("sc_cat_item");
if (grCatItem.get(cat_item)) {
var grUser = new GlideRecord("sys_user");
grUser.addQuery("sys_id", requested_for);
grUser.addActiveQuery();
grUser.query();
if (grUser.next()) {
var cart = new sn_sc.CartJS("childRequest");
cart.empty();
var request = {
sysparm_id: grCatItem.getValue("sys_id"),
sysparm_quantity: quantity,
sysparm_requested_for: grUser.getValue("sys_id"),
variables: variables,
};
cart.addToCart(request);
var checkoutInfo = cart.checkoutCart();
return checkoutInfo;
}
}
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-25-2024 11:26 PM
HISumanth,
unfortunately the proposed solution does not work.
I added a workflow timer (5 sec.) just before my task that creates several child items, but the situation stays the same.
Many RITM are created every 2 sec.
Do you have another idea?