How to create multiple test RITM records

Natahlie Nativi
Tera Contributor

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. 

1 ACCEPTED SOLUTION

@Natahlie Nativi 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

17 REPLIES 17

@Ankur Bawiskar 
I tried changing below part and the requested for was filled properly. It might be because of the array?

        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.requested_for = '62826bf03710200044e0bfc8bcbe5df1';
            gr.update();
                        // update REQ record as well
            var req = gr.request.getRefRecord();
            //req.requested_for = arr[count];
            req.requested_for = '62826bf03710200044e0bfc8bcbe5df1';
            req.update();
        }
 
The requested for you see in the list was from RITM table. 

@Natahlie Nativi 

Glad to know.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Natahlie Nativi 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Natahlie Nativi 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Natahlie Nativi 

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.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader