Alternative for the Global script include "Cart" function

Community Alums
Not applicable
Hi,
The below script in used in scheduled job to create a catalog item automatically when the scheduled job gets triggered.
But the "Cart" function called from script include mentioned as "This has been deprecated. Please dont use this Script Include for any use case. ServiceNow will deactivate the Script Include in coming release." 
I was checking all the docs but I did not find anything as the alternative for the "Cart" function. Can anyone suggest or provide the updated function to request a catalog item automatically.
Script written in Scheduled job:
var id = GlideGuid.generate(null); // Generate a new GUID
var cart = new Cart(id); // Instantiate a fresh cart using the random GUID from earlier
var myRitm = cart.addItem('854df61fdbjnb340529cfba12396194b');  // The sys_id of the catalog item to submit
cart.setVariable(myRitm ,'request_for_access', 100);
cart.setVariable(myRitm ,'requested_for_variable', user);
var request = cart.placeOrder();
 
Thanks,
Ripunjai.
3 REPLIES 3

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi @Community Alums 
There is new CartJS API that you can use.

CartJS | ServiceNow Developers


Thanks and Regards,

Saurabh Gupta

Community Alums
Not applicable

Hi @Saurabh Gupta  ,

Thanks for the response. Using this CartJS API, I can submit a request. But I found a issue with this.

First I need to use ->cart.orderNow(request); and later I need to change to-> cart.checkoutCart(request);. So, then I can submit a request. If I only use "orderNow" I can just add the item into cart but again if I remove everything from cart and change to "checkoutCart" then the order is submitted.

Apart from the above issue, there is a " Script Affected Record Summary" where the data shows list of records getting updating, inserting and deleting. Is this any issue or the expected behavior? 

var cart = new sn_sc.CartJS();
var newItem = cart.addToCart({
"sysparm_id": "854df61fdbdsds0529cfba66896194b",
"sysparm_quantity": "1",
"sysparm_requested_for": "00aad324fs2c151076fb628f7b4bcb3d",
"variables":{
'request_for_access' : '100'
}
});
var checkoutInfo = cart.orderNow(request);//for the first trigger

var checkoutInfo =cart.checkoutCart(request);//later I need to comment the above code and need to update to this code.

RipunjaiGurava_0-1703000556838.png

 

No Issues.


Thanks and Regards,

Saurabh Gupta