Attachment on Inbound Actions - CART API

azenith_moreno
Tera Contributor

Hi,

I have an inbound action that creates RITM thru CART API.

Everything is working fine, RITM is created but attachments are not included on the RITM ticket.

I might be missing something on my inbound action... any advices?

createRequest();

function createRequest() {

  var cart = new Cart();

  // add in cart

  var item = cart.addItem('62d832d56f8721006e3f4425eb3ee4b4');

  cart.setVariable(item, 'cleanupgensubject', email.subject.toString());

  cart.setVariable(item, 'cleanUpgenDetails', email.body_html);

  var cartmsg = "received from: " + email.origemail + "\n\n" + email.body_text;

  var rc = cart.placeOrder();

}

Thank you very much.

1 ACCEPTED SOLUTION

Hi Azenith,



You need to add the below code after placing the order in the cart:



var ritmSysID = "";


var ritmRec = new GlideRecord("sc_req_item");


ritmRec.addQuery("request", rc.sys_id);


ritmRec.query();


if(ritmRec.next()){


        ritmSysID = ritmRec.sys_id;


}



Thanks,


CK


View solution in original post

12 REPLIES 12

ck_phenix
Kilo Expert

Hi Azenith,



Try adding the below script to your Inbound action and then it should create attachments to your RITM ticket:



var emailRec = new GlideRecord("sys_email");


emailRec.addQuery("uid", email.uid);


emailRec.orderByDesc("sys_created_on")


emailRec.query();


if(emailRec.next()){


        Packages.com.glide.ui.SysAttachment("sys_email", emailRec.sys_id, "sc_req_item", <ritm_sys_id>);


}




Thanks,


CK


Brad Tilton
ServiceNow Employee
ServiceNow Employee

You can do something like what CK suggests.



In an inbound email, ServiceNow automatically copies the attachments to the sys_email record, so you can use the following article combined with CK's script to copy the attachment to the RITM record. Since the catalog api only gives you the REQ id, you will need to use that to query to the item id in order to copy the attachment.



Copy Attachments from Record to Record - ServiceNow Wiki


azenith_moreno
Tera Contributor

Thanks Brad and CK. Having some difficulties though on getting the sys id of the RITM created from the inbound action..can you kindly provide some more information on how to achieve this? thank you.


Hi Azenith,



You need to add the below code after placing the order in the cart:



var ritmSysID = "";


var ritmRec = new GlideRecord("sc_req_item");


ritmRec.addQuery("request", rc.sys_id);


ritmRec.query();


if(ritmRec.next()){


        ritmSysID = ritmRec.sys_id;


}



Thanks,


CK