- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2025 05:55 PM
I need to create 200+ RITM to test a functionality of our portal.
What is the best way to do it?
I think using a script might be a bit hard since we need to set values for the variables.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2025 09:44 PM
the user who is running the script i.e. Admin will be populated in requested_for field
You can update the requested_for field on REQ as well
try {
var count = 5;
//user sysID
var arr = ['62826bf03710200044e0bfc8bcbe5df1', 'a8f98bb0eb32010045e1a5115206fe3a', '0a826bf03710200044e0bfc8bcbe5d7a', '22826bf03710200044e0bfc8bcbe5dec', 'a2826bf03710200044e0bfc8bcbe5ded'];
for (var i = 0; i < count; i++) {
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
//add your requested item to the cart by sys_id of the catalog item
var item = cart.addItem('c7eb778f97d2415021983d1e6253af7b', 1);
//fill in the variables on the request item form
// asset is name of variable and type is reference so give sysId
cart.setVariable(item, "select_group_which_needs_to_be_cloned", "d625dccec0a8016700a222a0f7900d06");
cart.setVariable(item, "business_justification", "test");
var rc = cart.placeOrder();
gs.info(rc.number);
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request.number", rc.number.toString());
gr.query();
if (gr.next()) {
gr.requested_for = arr[count];
gr.update();
// update REQ record as well
var req = gr.request.getRefRecord();
req.requested_for = arr[count];
req.update();
}
}
} catch (ex) {
gs.info(ex);
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-05-2025 08:03 PM
Even tho the array was not working, but you code still works. Thank you for helping!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2025 07:22 PM - edited 02-04-2025 07:23 PM
Hi @Natahlie Nativi ,
All RITM belongs to same catalog item with same variable values or same catalog with different variable values or difference catalog items with respective variable values.
In either case, you need to prepare data for all 200 RITMs and store some where in stage table or prepare in xls ( for upload and run the transform map on it ).
After than, write a script using the Cart class and create the request item for each record of stage table ( of from xls file). You need to created RITM via script and link the request with RITM and catalog workflow will do the rest.
-Thanks,
AshishKM
Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2025 08:43 PM
As others mentioned, you could use a script; alternatively, you could set this up in Flow Designer if you aren't comfortable with scripting. Set up a flow that triggers on the change of a specific record, and then I think you can use a Do Until flow action (you may need to set up a counter variable) to get this firing. I will note performance. I would recommend the script route.
Another option: transform map. Another option: if you really want to dig into some code, you could try to replicate whatever controls the Create Bulk HR Case.