- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2020 08:07 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2020 10:10 AM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2020 08:52 AM
After your placeOrder, you can use a GlideRecord to set other fields. Something like this:
var ritmRec = new GlideRecord("sc_req_item");
ritmRec.addQuery("request", rc.sys_id);
ritmRec.query();
if(ritmRec.next()){
ritmRec.special_instructions = '12345';
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2020 09:27 AM
I'm still having a problem with this it turns out.
Here's my code. According to the log output grRequest.special_instructions is getting set OK but when I go to the request and check special_instructions it is blank.
I understand that we are not supposed to use update() within a business rule so how can I make the value stick?
(function executeRule(current, previous /*null when async*/) {
var cartId = GlideGuid.generate(null);
var cart = new Cart(cartId);
var item = cart.addItem('b70cc309db2797804aba70600f961934');
var rc = cart.placeOrder(); // rc = request object
gs.log("RGK - Created OK - number = " + rc.number);
var count = 0;
var grRequest = new GlideRecord("sc_request");
grRequest.addQuery("sys_id", rc.sys_id);
grRequest.query();
while(grRequest.next()){
count++;
grRequest.special_instructions = current.description;
gs.log("RGK - 111" + current.description); // OK
gs.log("RGK - 222" + grRequest.special_instructions); // OK
}
gs.log("RGK - Count = " + count);
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2020 10:10 AM
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();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-17-2020 02:15 PM
Thanks I've got it sorted now
