Cart API - Variable Set Field not populated

hanaphouse
Giga Guru

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();
1 ACCEPTED SOLUTION

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();

View solution in original post

8 REPLIES 8

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!

DrewW
Mega Sage
Mega Sage

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

 

Isn't cartJS for scoped application?

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.