- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2020 12:32 PM
When attempting to order a custom cart with the below code (within the Server Script of a Service Portal widget), ServiceNow seems to be creating a new DEFAULT cart automatically.
cartJS = new sn_sc.CartJS("test");
/* Add catalog item to cart here */
var request = cartJS.checkoutCart();
After cartJS.checkoutCart(); runs, I look at sc_cart table and find two DEFAULT carts for my user. However, if I add a user action in between the creation and checkout so that I can slow down the process, I shows my "test" cart being created and it being ordered. So the code, works, but it seems there's a bug in the API.
Is anyone else seeing this?
Thanks,
David Hadwin
Solved! Go to Solution.
- Labels:
-
Service Catalog
-
Service Portal
- 4,157 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2020 06:36 AM
I figured this out myself. It was a blunder by me. I had a sys_id reference to the cart "test" that already had been checked out, but was unbeknownst to me, updating it again. I didn't realize that passing in a non-existent sys_id to a GlideRecord would create a new cart.
var cartGR = new GlideRecord('sc_cart');
cartGR.get(cartSYS);
then at the end of my code, I was calling
cartGR.update();
and since the only thing I had inserted into this new cart was the sys_id, the name defaulted to DEFAULT.
I hope this helps someone in the future,
David Hadwin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-29-2020 10:50 PM
Hi David,
I have tried the following and that works as expected:
var cartJS = new sn_sc.CartJS("test");
var item =
{
'sysparm_id': '0d08837237153000158bbfc8bcbe5d02',
'sysparm_quantity': '1',
'variables':{
'carrier': 'at_and_t_mobility',
'data_plan': '500MB',
'duration': 'eighteen_months',
'color': 'slate',
'storage': 'sixtyfour'
}};
var cartDetails = cartJS.addToCart(item);
var request = cartJS.checkoutCart();
The "test"-cart contains the iPhone 5 from the script.
Can you try and delete the 2 default carts. Open the portal so 1 default is there. And then run the script again. See if a 2nd default is generated?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2020 10:12 AM
Hi Willem,
I see your "test" cart still visible, was this after checkout?
I've tried clearing all my DEFAULT carts, do you know if there's a difference between a cart with the name DEFAULT and an actual DEFAULT cart created when the cart name passed into the API is nil?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-03-2020 12:18 PM
Oh sorry, I commented out the checkout to show you I had the test cart. If I do the checkout it is not showing.
If you do not specify a name it will use the Default. For me it just updates my current default (I again commented out the checkout):
If I remove the default cart and create test:
Can you see if the user on the cart is the same?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-06-2020 06:36 AM
I figured this out myself. It was a blunder by me. I had a sys_id reference to the cart "test" that already had been checked out, but was unbeknownst to me, updating it again. I didn't realize that passing in a non-existent sys_id to a GlideRecord would create a new cart.
var cartGR = new GlideRecord('sc_cart');
cartGR.get(cartSYS);
then at the end of my code, I was calling
cartGR.update();
and since the only thing I had inserted into this new cart was the sys_id, the name defaulted to DEFAULT.
I hope this helps someone in the future,
David Hadwin