- 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-04-2025 11:44 PM
@Ankur Bawiskar
I tried changing below part and the requested for was filled properly. It might be because of the array?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2025 11:58 PM
Glad to know.
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 12:00 AM
check this link for extra help, response from Cody and Tim
How to set requested for in RITM using Cart APi is it possible?
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 07:58 PM
Hope you are doing good.
Did my reply answer your question?
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-04-2025 11:46 PM
I verified and the code I shared doesn't update the requested_for field on RITM and REQ
But when I queried it separately it allowed to update.
Strange behavior.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader