
- 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-24-2019 07:02 PM
Hi,
Did you try to check by adding log statements whether ritm sys id is coming or not?
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-24-2019 09:26 PM
Thankyou Ankur, I have done as you suggested above and to no avail (the attachment does not copy across). I added logging and it brings in both my sys id for the ritm and the sys_email sys id also without issue. So I am still preplexed-
with gs.log the "ritmSYSID" gives me a <sysid of the ritm>
with gs.log the "1. sysid of email_log" gives me a <sysid of the associated email_log>
I have confirmed these match the two records in question!
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','<SYSID of assignment 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();
gs.sleep(3000);
var ritmSysID = "";
var ritm = new GlideRecord("sc_req_item");
ritm.addQuery("request",ritmRec.sys_id);
ritm.query();
if(ritm.next()){
ritmSysID = ritmRec.getUniqueValue();
}
gs.log("ritmSYSID "+ ritmSysID);
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);
gs.log("1. sysid of email_log "+ email_sys);
gs.log("1. second sysid of ritmsysid " + ritmSysID);
} else {
var email_sys = 0;
GlideSysAttachment.copy('sys_email', email_sys, 'sc_req_item', ritmSysID);
gs.log("2. sysid of email_log "+ email_sys);
gs.log("2. third sysid of ritmsysid " + ritmSysID);
}
}
event.state="stop_processing";
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-24-2019 11:32 PM
Hi,
Is the attachment present on the email log record?
Regards
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 07:47 PM
Hi Ankur, yes it is....just won't copy. Is it because potentially I am using a workflow with that catalog item I am calling...and perhaps it is waiting on the workflow to complete (even though I do have a wait time in my script)? Can I run this copy somehow in the workflow instead of the inbound email?