CartJS not returning sys_id of newly created RITM

nirwan_ritik
Tera Contributor

I am using CartJS to create a ritm manually in a script. When I used Cart API, I was getting sys_id of the newly created RITM in rc.sys_id. But with CartJS, I am not getting it. I want the sys_id for post creation updates on the same ritm in the same script. How to get it?

var rgr = new GlideRecord('sc_req_item');
rgr.addQuery('sys_id', 'xyz');
rgr.query();

while (rgr.next()){  
    var rf = rgr.requested_for;
    var cart = new sn_sc.CartJS();
    cart.setRequestedFor(rf);
    var item = { 
        'sysparm_id': 'xyz',
        'sysparm_quantity': '1',        
        'variables': {
            "business_justification": 'BJ Test 2'
        }
    };
    cart.addToCart(item);
    cart.checkoutCart();
}

3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@nirwan_ritik 

for cartJS you need to get the json response and then parse and get the REQ sysId

If the two-step checkout is disabled then this is the output of checkoutCart() function

AnkurBawiskar_0-1701755257757.png

 

check this docs link

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

Hi Ankur, 

I tried the method to retrieve the request id as suggested in the document. I got an [object object]. But when I stringify it, it returned undefined. Could you please assist me with the code updation in above code.


Thanks

nirwan_ritik
Tera Contributor

I had a syntax error. Fixed it. It worked. Thanks