- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2016 06:39 PM
Hi all,
I'm having trouble populating variables of RITMs created from the cart api. My code is below, any suggestions or hints are greatly appreciated. Thanks again,
createRequest();
function createRequest() {
var cat_id='';
if(email.body.item != undefined && email.body.item!='') {
var item=email.body.item.trim();
var gr= new GlideRecord('sc_cat_item');
gr.get('name',item);
cat_id=gr.getValue('sys_id');
var cart = new Cart();
cart.addItem(cat_id);
var user = new GlideRecord('sys_user');
cart.get(gr.getValue('requested_for'));
// set requested for, substitute your requested for
//Set Variables in your Cart Item
cart.setVariable(item, 'requested_for', 'sys_user');
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();
}
}
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2016 07:10 PM
Here is your code. copy it as is
createRequest();
function createRequest() {
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, substitute your 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();
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2016 07:10 PM
Here is your code. copy it as is
createRequest();
function createRequest() {
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, substitute your 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();
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2016 07:17 PM
Thank you Abhinay! It works like a charm. If you don't mind, could you point me in the right direction of creating a REQ business rule? This is basically to allow RITMs created not through the service catalog to have REQ and eventually have the workflows firing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2016 07:31 PM
Wow.. great that you make it worked. The solution looks pretty much similar what I have said earlier.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-30-2020 06:39 PM
Hi,
You've mentioned commented line "//Set Variables in your Cart Item". So do you mean, actual variables (maybe direct variables or part of single row or multi row variable set) created on that particular catalog item.? or are you setting values to fields on the sc_req_item table.?
The reason of asking this is - I am trying to find a way to set values to actual variables (item_option_new table), not the fields? Will the similar above code help me set values to variables on my catalog item, if its possible as a first thing?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-05-2016 07:20 PM
I am sorry, I did not get what you are saying. Why do you want the business rule?