Cart API - Is GlideGuid.generate(null) really needed when using Cart API?

hanaphouse
Giga Guru

I would like to understand the Cart API better and I want to know if it is release necessary to execute GlideGuid.generate(null)?

Version #1:

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);

Version #2:

var cart = new Cart();

 

Can I just use version 2 or should I really invoke version #1? What is the difference?

1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

Hi,

It's to ensure you're using a unique cart. As an example, if you browse the service portal and add an item to your basket, a cart will be presented in the sc_cart table for your user profile with a name of DEFAULT. If you were to then use new Cart().... and not specify a unique name, you would be calling the cart with that default cart and could inadvertently place an order/request with additional RITMs. 

As you can see from below, in the portal I've added an item to my basket/cart but haven't checked out.

find_real_file.png

If I was to then use new Cart() and request say a phone via script, I would submit both the email account and phone under a single REQ.

Calling Version 1 of the script you attached you can see two cart entries, 1 with a completely unique name of a sys_id.

find_real_file.png

View solution in original post

1 REPLY 1

Kieran Anson
Kilo Patron

Hi,

It's to ensure you're using a unique cart. As an example, if you browse the service portal and add an item to your basket, a cart will be presented in the sc_cart table for your user profile with a name of DEFAULT. If you were to then use new Cart().... and not specify a unique name, you would be calling the cart with that default cart and could inadvertently place an order/request with additional RITMs. 

As you can see from below, in the portal I've added an item to my basket/cart but haven't checked out.

find_real_file.png

If I was to then use new Cart() and request say a phone via script, I would submit both the email account and phone under a single REQ.

Calling Version 1 of the script you attached you can see two cart entries, 1 with a completely unique name of a sys_id.

find_real_file.png