- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2020 01:56 PM
I have a requirement to auto-create catalog request through email inbound action, I set up the inbound on sc_req_item table but I am not doing a current.insert() otherwise it will double submit the request(as the order is already placed through Cart API), things working fine but one problem I don't find a way to attach the original inbound email to the Activity field, any idea?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 10:32 PM
Hi,
Please follow the below script:-
Option 1: Add Message to Comments
Inbound Action: Create Requested Item
Table: sc_req_item
Condition: <your condition here>
Script:-
createRequest();
function createRequest() {
var cart = new Cart();
// add in cart
var item = cart.addItem('8c2a069c242cb800839dec45b40a7496');
// set requested for
cart.setVariable(item, 'requested_for', '5136503cc611227c0183e96598c4f706');
cart.setVariable(item, 'request_short_description', email.subject.toString());
cart.setVariable(item, 'request_description', email.body_html);
cart.setVariable(item, 'request_type', 'others');
// set application
cart.setVariable(item, 'application', '3243d574bd05300071578913764fb117');
// set assignment group
cart.setVariable(item, 'assignment_group', '4769d53099266800d7ea6843423a4c2b');
cart.setVariable(item, 'priority', 'PR3');
var cartmsg = "received from: " + email.origemail + "\n\n" + email.body_text;
cart.setVariable(item,'comments',cartmsg);
var rc = cart.placeOrder();
}
Option 2: Generate without Cart API
Inbound Action: Create Requested Item
Table: sc_req_item
Condition: <your condition here>
Script:
createRequest();
function createRequest() {
//Create Request
var grRequest = new GlideRecord ("sc_request");
grRequest.initialize();
grRequest.requested_for = '5136503cc611227c0183e96598c4f706';
grRequest.short_description = email.subject.toString();
grRequest.description = "received from: " + email.origemail + "\n\n" + email.body_text;
var requestSysId = grRequest.insert();
//Create Request Item
current.requested_for = '5136503cc611227c0183e96598c4f706';
current.short_description = email.subject.toString();
current.description = "received from: " + email.origemail + "\n\n" + email.body_text;
current.cat_item = '8c2a069c242cb800839dec45b40a7496';
current.parent = requestSysId;
current.request = requestSysId;
current.request_type = 'others';
current.application= '3243d574bd05300071578913764fb117';
current.assignment_group='4769d53099266800d7ea6843423a4c2b';
current.priority= 'PR3';
current.insert();
}
If i was able to solve your query, please mark my answer correct and helpful.
Thanks & Regards
Prasant kumar sahu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 08:33 AM
Can you share script that you have inbound action.
basically you will update instance field on email with RITM sys_id
so like
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", rc.sys_id);
gr.query();
if (gr.next()) {
current.instance = gr.sys_id;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2020 10:32 PM
Hi,
Please follow the below script:-
Option 1: Add Message to Comments
Inbound Action: Create Requested Item
Table: sc_req_item
Condition: <your condition here>
Script:-
createRequest();
function createRequest() {
var cart = new Cart();
// add in cart
var item = cart.addItem('8c2a069c242cb800839dec45b40a7496');
// set requested for
cart.setVariable(item, 'requested_for', '5136503cc611227c0183e96598c4f706');
cart.setVariable(item, 'request_short_description', email.subject.toString());
cart.setVariable(item, 'request_description', email.body_html);
cart.setVariable(item, 'request_type', 'others');
// set application
cart.setVariable(item, 'application', '3243d574bd05300071578913764fb117');
// set assignment group
cart.setVariable(item, 'assignment_group', '4769d53099266800d7ea6843423a4c2b');
cart.setVariable(item, 'priority', 'PR3');
var cartmsg = "received from: " + email.origemail + "\n\n" + email.body_text;
cart.setVariable(item,'comments',cartmsg);
var rc = cart.placeOrder();
}
Option 2: Generate without Cart API
Inbound Action: Create Requested Item
Table: sc_req_item
Condition: <your condition here>
Script:
createRequest();
function createRequest() {
//Create Request
var grRequest = new GlideRecord ("sc_request");
grRequest.initialize();
grRequest.requested_for = '5136503cc611227c0183e96598c4f706';
grRequest.short_description = email.subject.toString();
grRequest.description = "received from: " + email.origemail + "\n\n" + email.body_text;
var requestSysId = grRequest.insert();
//Create Request Item
current.requested_for = '5136503cc611227c0183e96598c4f706';
current.short_description = email.subject.toString();
current.description = "received from: " + email.origemail + "\n\n" + email.body_text;
current.cat_item = '8c2a069c242cb800839dec45b40a7496';
current.parent = requestSysId;
current.request = requestSysId;
current.request_type = 'others';
current.application= '3243d574bd05300071578913764fb117';
current.assignment_group='4769d53099266800d7ea6843423a4c2b';
current.priority= 'PR3';
current.insert();
}
If i was able to solve your query, please mark my answer correct and helpful.
Thanks & Regards
Prasant kumar sahu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2021 07:50 PM
Hi Prasant
Thank you for the scripts you've provided. I've had a little success with them. I still have a couple of minor (and frustrating) issues which I hope you (or someone) can assist with.
Option 1 - creates a blank request item, instead of using the one specified in the script and doesn't fill in any details (subject or body) from the email. It's also not on any workflow that we are using.
Option 2 - fills in all the details from the email, but doesn't have an element which calls a specific catalogue item. I'd be very happy with this option, if I can get it to use the correct item (and corresponding workflow).
We are running Paris.
The item is simply to generate an RITM from the email updating short description and description fields. No other item specific variables, it's all in the email. The workflow sets it straight to approved and fulfillment stage. Generates only 1 task.
SCRIPT FOR OPTION 1 (using cart api):
createRequest();
function createRequest() {
var cart = new Cart();
// add in cart, substitute your cat item sys_id
var item = cart.addItem('ca63c3e3db7b24107214b5ec34961986');
// set requested for, substitute your requested for
//Set Variables in your Cart Item
cart.setVariable(item, 'requested_for', 'f6ec8b714f610600dde420201310c751');
cart.setVariable(item, 'request_short_description', email.subject.toString());
cart.setVariable(item, 'request_description', email.body_html);
var cartmsg = "received from: " + email.origemail + "\n\n" + email.body_text;
cart.setVariable(item,'comments',cartmsg);
var rc = cart.placeOrder();
}
SCRIPT FOR OPTION 2 (NO cart api):
createRequest();
function createRequest() {
//Create Request
var grRequest = new GlideRecord ("sc_request");
grRequest.initialize();
grRequest.requested_for = 'f6ec8b714f610600dde420201310c751';
grRequest.short_description = email.subject.toString();
grRequest.description = "received from: " + email.origemail + "\n\n" + email.body_text;
var requestSysId = grRequest.insert();
//Create Request Item
current.requested_for = 'f6ec8b714f610600dde420201310c751';
current.short_description = email.subject.toString();
current.description = "received from: " + email.origemail + "\n\n" + email.body_text;
current.cat_item = '8c2a069c242cb800839dec45b40a7496';
current.parent = requestSysId;
current.request = requestSysId;
current.contact_type = 'email';
current.assignment_group= '35f1f284dbd0585499fccae43a961961';
current.insert();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-15-2021 11:22 AM
Prasant,
Can you also help with a line for adding the assignment group from the email? I have an ask that when this runs it will be different each time. If I can get that to set on the RITM, then I should be able to set the task assignment group in the workflow (I think?)
Appreciate any guidance. This one is tough.
Thank you,
Jamie