- 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 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 09:50 PM
@Ankur Bawiskar Apologies but I tried this code and still the requested for is still the system admin..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2025 11:00 PM
please share your complete code.
are you getting rc.number correctly if you print in logs?
when script runs the field requested_for will be populated with logged in user and we are updating it via GlideRecord
which requested for you are referring? RITM table or REQ table?
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:27 PM
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); }
This is the code that I was using and when I run it this is the result.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-04-2025 11:32 PM
can you share log for this line?
Also the Requested for you see on list is from RITM table or REQ table?
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