Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Cart API - Setting Request field

RichGK1
Mega Expert

I'm using the Cart API to create a cart and an item and subsequent request. This all gets created OK but when trying to set the special_instructions field on the request it does not get set.

Can anyone tell me what I am doing wrong?

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('b70cc309db2797804aba70600f961934');
var rc = cart.placeOrder(); // rc = request
gs.log("RGK - Created OK - number = " + rc.number);
gs.log("RGK - Created OK - requested_for = " + rc.requested_for);
	
//rc.special_instructions = current.description; // not getting set
rc.special_instructions = "12345"; // not setting
1 ACCEPTED SOLUTION

Cart runs on request. Special instructions is on the request table. Your gliderecord is also on request. So instead of using gliderecord, change your script adding below between var item and var rc:

var cartGR = cart.getCart()
cartGR.special_instructions = current.description;
cartGR.update();

View solution in original post

5 REPLIES 5

ktruong
Tera Contributor

Using the script above such as

var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('b70cc309db2797804aba70600f961934');
var rc = cart.placeOrder(); // rc = request
gs.log("RGK - Created OK - number = " + rc.number);
gs.log("RGK - Created OK - requested_for = " + rc.requested_for);
	
//rc.special_instructions = current.description; // not getting set
rc.special_instructions = "12345"; // not setting

 I found that delivery_address(add Notes/Comment) has value 'CA'.  I am just wondering why it has default value 'CA' for delivery_address
test.png