- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2021 09:17 AM
I am trying to fill out a variable within a variable through Cart API, however, this doesn't seem to work.
- Variable Set: vset_fields
- Variable Set Field # (a multi-line field): vset_fields_test
What could be the issue there?
var cart = new Cart();
var item = '6d0f8e1c81df2500772e95d75e286264';
cart.addItem(item);
cart.setVariable(item,'vset_fields_test','test');
var scREQ = cart.placeOrder();
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2021 09:06 AM
I think I figured out what's wrong with the script. I should store the .addItem() in a variable then use that variable to set the catalog item variables.
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = '6d0f8e1c81df2500772e95d75e286264';
var ritm = cart.addItem(item);
cart.setVariable(ritm,'vset_fields_test','test');
var scREQ = cart.placeOrder();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2021 09:48 AM
Hello,
Yep, as shown in the documentation I've linked above with the overall point being you can use setVariable with any variables associated, regardless of variable set, etc.
Please mark reply as Helpful/Correct, if applicable. Thanks!
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-30-2021 01:23 PM
Did you know that there is a new CartJS API and that ServiceNow is not updating the Cart API anymore.
https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/sn_sc-namespace/c_CartJSScoped?navFilter=cartjs
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2021 08:46 AM
Isn't cartJS for scoped application?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-31-2021 11:15 AM
Its for both. I recently logged a case because the new requested for field type does not work with the Cart API and was told it will not and they are not doing anymore dev on it and if you would like the new Requested For var type to work properly you have to use the new CartJS API. My scheduled job is running in the global scope and I could use it so it does work to a point. I have yet to get it to work when I add multiple catalog items to the cart but it works great if all you order is one thing in your script. But that maybe UE, still waiting to find out from support.