Setting RITM fields using Cart API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2016 06:41 AM
Hi all,
I was wondering if there is a way to populate fields (not variables) on RITM forms? Everything I've read talks about populating variables but I'd like to have the fields set as well based on what users send to SN via emails. Any help or suggestions is greatly appreciated. Thanks again,
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2016 06:45 AM
Hi James,
The API only allows you to set variables, so the standard way to populate fields is to use the request sysid that the cart api gives you in order query the requested items associated with the request and populate field values.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2016 06:54 AM
Thank you Brad, could you help me with what the code might look like for this?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2016 06:48 AM
You can do something like this in your inbound action
var rc = cart.placeOrder();
var gr= new GlideRecord('sc_req_item');
gr.addQuery('request',rc.sys_id);
gr.query();
while(gr.next())
gr.short_description=email.subject;
//set your fields here
gr.update();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-18-2016 06:54 AM
Thank you Abhinay and Brad
My code looks like this:
var cat_id='';
if(email.body.item != undefined && email.body.item!='') {
var cat_item=email.body.item.trim();
var gr= new GlideRecord('sc_cat_item');
gr.get('name',cat_item);
cat_id=gr.getValue('sys_id');
var cart = new Cart();
var item=cart.addItem(cat_id);
var user = new GlideRecord('sys_user');
if(user.get('email',email.from.toString())){
// set requested for
//Set Variables in your Cart Item
cart.setVariable(item, 'requested_for', user.getValue('sys_id'));
cart.setVariable(item, 'request_short_description', email.subject.toString());
cart.setVariable(item, 'requested_for_department', user.department);
cart.setVariable(item, 'requested_for_username', user.user_name);
cart.setVariable(item, 'requested_for_phone', user.phone);
cart.setVariable(item, 'requested_for_budgetcode', user.cost_center);
cart.setVariable(item, 'requested_for_company', user.company);
}
var cartmsg = "received from: " + email.origemail + "\n\n" + email.body_text;
cart.setVariable(item,'comments',cartmsg);
var rc = cart.placeOrder();
}
}
Are you saying I add my fields after the underlined line?