CartJS not returning sys_id of newly created RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2023 09:35 PM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-04-2023 09:48 PM
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
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
‎12-05-2023 11:03 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-06-2023 11:00 AM
I had a syntax error. Fixed it. It worked. Thanks