The CreatorCon Call for Content is officially open! Get started here.

Inbound Email Action for RITM to copy attachment from sys_email to sc_req_item.

mattmm
Kilo Sage

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";
1 ACCEPTED SOLUTION

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!

 

 

View solution in original post

9 REPLIES 9

On further inspection the sysid it is bringing back is actually the Request not the Requested Item! Yet my script is creating the ritm?

 

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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!

 

 

Omkar Mone
Mega Sage

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

Hi Omkar, no, the uid is not in the body of the email, it's a field in the sys_email table populated with the userid.

find_real_file.png

 

find_real_file.png