
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2019 04:14 PM
I have an inbound action to use shopping cart to create a RITM, but I need to also attach any attachments with inbound emails to the associated RITM when it is created.
I am using the GlidSysAttachment property but it is not working as expected. The attachment comes into the sys_email table but won't copy despite my code below?
Any advice?
createRequest();
function createRequest() {
var cart = new Cart();
var item = cart.addItem('<SYSID of Cat Item>'); //sys_id of the catalog item I want to fire
cart.setVariable(item, 'ps_desc', email.body_text); //sets catalog variable to email's body
cart.setVariable(item, 'ps_short_desc', email.subject);
cart.setVariable(item, 'assignment_group','<Sys Id of Assignemnt Group>');
cart.setVariable(item, 'requested_for', current.caller_id);
var cartmsg = "received from: " + email.origemail + "\n\n" + email.body_text;
cart.setVariable(item,'comments',cartmsg);
var ritmRec = cart.placeOrder();
var ritmSysID = "";
var ritm = new GlideRecord("sc_req_item");
ritm.addQuery("request",ritmRec.sys_id);
ritm.query();
if(ritm.next()){
ritmSysID = ritmRec.sys_id;
}
var email_log = new GlideRecord('sys_email');
email_log.addQuery('uid', email.uid);
email_log.orderByDesc('sys_created_on');
email_log.query();
if (email_log.next()) {
var email_sys = email_log.sys_id;
GlideSysAttachment.copy('sys_email', email_sys, 'sc_req_item', ritmSysID);
} else {
var email_sys = 0;
GlideSysAttachment.copy('sys_email', email_sys, 'sc_req_item', ritmSysID);
}
}
event.state="stop_processing";
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2019 09:40 PM
My colleague got it based off what I was saying above! I was running this Inbound action on the sc_req_item table, he simply changed to the request table....and it works!!! Please note, for anyone reading this that the above will work, but has to be on the request table for the inbound action of course!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2019 08:39 PM
On further inspection the sysid it is bringing back is actually the Request not the Requested Item! Yet my script is creating the ritm?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2019 09:15 PM
Hi Matt,
when you use that script include for Cart() and use placeOrder() then it created request and ritm both; no need to worry
So that is the issue; the sys_id is of request and not RITM
now after code change is it working fine?
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2019 09:40 PM
My colleague got it based off what I was saying above! I was running this Inbound action on the sc_req_item table, he simply changed to the request table....and it works!!! Please note, for anyone reading this that the above will work, but has to be on the request table for the inbound action of course!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2019 11:35 PM
Hi
I see a problem in this line -
email_log.addQuery('uid', email.uid);
Would you help me in understanding what are you trying to do here? Is uid something from the email body? I would recommend you to try logs for email.uid
Also try with
email_log.addQuery('uid', email.body.uid);
Hope this helps.
Regards
Omkar Mone

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-25-2019 07:43 PM