
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2018 02:24 PM
I have an inbound action that is creating an RITM and single catalog tasks. That part is working as expected. however, the attachments are not being copied to the RITM via email. I have tried several of the attempts on the community and its just not copying them over.
I am on Kingston patch 6.
see code below. Any help would be greatly appreciated.
createRequest();
function createRequest() {
var cart = new Cart();
// add in cart
var item = cart.addItem('d81c4666db365b00d901dd0b5e961925');
// set requested for
cart.setVariable(item, 'vs_from', email.origemail);
cart.setVariable(item, 'vs_short_description', email.subject.toString());
cart.setVariable(item, 'vs_description', email.body_text);
var cartmsg = "received from: " + email.origemail + "\n\n" + email.body_text;
cart.setVariable(item,'comments',cartmsg);
var ritmRec = cart.placeOrder();
}
var ritmSysID = "";
var ritmRec = new GlideRecord("sc_req_item");
ritmRec.addQuery("request", rc.sys_id);
ritmRec.query();
if(ritmRec.next()){
ritmSysID = ritmRec.sys_id;
}
var emailRec = new GlideRecord("sys_email");
emailRec.addQuery("uid", email.uid);
emailRec.orderByDesc("sys_created_on");
emailRec.query();
if(emailRec.next()){
GlideSysAttachment.copy("sys_email", emailRec.sys_id, "sc_req_item", ritmRec.sys_id);
}
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2018 06:53 AM
This same I did and it worked, I made few changes lets see the output:
createRequest();
function createRequest() {
var cart = new Cart();
// add in cart
var item = cart.addItem('d81c4666db365b00d901dd0b5e961925');
// set requested for
cart.setVariable(item, 'vs_from', email.origemail);
cart.setVariable(item, 'vs_short_description', email.subject.toString());
cart.setVariable(item, 'vs_description', email.body_text);
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); //Changed
ritm.query();
if(ritm.next()){
ritmSysID = ritmRec.sys_id; //Changed
}//Changed
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);
}
}
Thanks
Shashikant
Hit Helpful or Correct on the impact of response.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2018 03:34 PM
Fix your code
createRequest();
function createRequest() {
var cart = new Cart();
// add in cart
var item = cart.addItem('d81c4666db365b00d901dd0b5e961925');
// set requested for
cart.setVariable(item, 'vs_from', email.origemail);
cart.setVariable(item, 'vs_short_description', email.subject.toString());
cart.setVariable(item, 'vs_description', email.body_text);
var cartmsg = "received from: " + email.origemail + "\n\n" + email.body_text;
cart.setVariable(item,'comments',cartmsg);
var ritmRec = cart.placeOrder();
var ritmSysID = "";
var ritmRec = new GlideRecord("sc_req_item");
ritmRec.addQuery("request",ritmRec);
ritmRec.query();
if(ritmRec.next()){
ritmSysID = ritmRec.sys_id;
var emailRec = new GlideRecord("sys_email");
emailRec.addQuery("uid", email.uid);
emailRec.orderByDesc("sys_created_on");
emailRec.query();
if(emailRec.next()){
GlideSysAttachment.copy("sys_email", emailRec.sys_id, "sc_req_item",ritmSysID);
}
}
Please mark this response as correct or helpful if it assisted you with your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2018 06:12 AM
I tried that code as well, still not getting attachments copied from the sys_email to the RITM.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2018 06:34 AM
I have tried several different modifications to the script. The RITM is being created correctly. no issues with it. But the attachments are not being copied over still.
here is my current code. the suggestion above caused a duplication to the declared variable ritmRec and didn't work to copy the attachment. so i modified it a bit to declare a clean variable.
createRequest();
function createRequest() {
var cart = new Cart();
// add in cart
var item = cart.addItem('d81c4666db365b00d901dd0b5e961925');
// set requested for
cart.setVariable(item, 'vs_from', email.origemail);
cart.setVariable(item, 'vs_short_description', email.subject.toString());
cart.setVariable(item, 'vs_description', email.body_text);
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",ritm);
ritm.query();
if(ritm.next()){
ritmSysID = ritm.sys_id;
var emailRec = new GlideRecord("sys_email");
emailRec.addQuery("uid", email.uid);
emailRec.orderByDesc("sys_created_on");
emailRec.query();
if(emailRec.next()){
GlideSysAttachment.copy("sys_email", emailRec.sys_id, "sc_req_item",ritmSysID);
}
}
}
has anyone found a way to make this work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2018 06:40 AM
Can you apply below code:
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);
}
}
Thanks
Shashikant
Hit Helpful or Correct on the impact of response.