i want to add attachment in the ritm from inbound email action.

NeethuB
Tera Contributor
(function runAction(/*GlideRecord*/ current, /*GlideRecord*/ event, /*EmailWrapper*/ email, /*ScopedEmailLogger*/ logger, /*EmailClassifier*/ classifier) {

    // Implement email action here
    var cartID=GlideGuid.generate(null);
    var cart= new Cart(cartID);
    var item= cart.addItem('158edf4a2bacfe10eacaf2a6d391bf51');
    //cart.setVariable(item,'short_description','test short');
    cart.setVariable(item,' requested_for',gs.getUserID());
    cart.setVariable(item,'short_description',email.subject);
    cart.setVariable(item,'subject','This request created when the caller sended email for creating a request');
    cart.setVariable(item,'description',email.body_text);
    var rc=cart.placeOrder();

    var ritm=new GlideRecord("sc_req_item");
    ritm.addQuery('request',rc.sys_id);
    ritm.query();
    if(ritm.next())
    {
        ritm.short_description = email.subject.toString();
        ritm.contact_type="email";
        ritm.update();
    }

})(current, event, email, logger, classifier);


This is the code . Can you pls help me
1 ACCEPTED SOLUTION

@NeethuB 

So as per your information the RITM is getting created and the incoming file to email should get copied to RITM

please update code as this

var ritm=new GlideRecord("sc_req_item");
    ritm.addQuery('request',rc.sys_id);
    ritm.query();
    if(ritm.next())
    {
        ritm.short_description = email.subject.toString();
        ritm.contact_type="email";
        ritm.update();
new GlideSysAttachment().copy('sys_email', sys_email.sys_id, 'sc_req_item', ritm.sys_id);
    }

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

View solution in original post

6 REPLIES 6

Sarthak Kashyap
Kilo Sage

Hi @NeethuB ,

 

Can you please add one line in your code

 

 

GlideSysAttachment.copy('sourceTable',sourceSysID, 'targetTable',targetSysID);

 

Please mark my answer correct and helpful if this works for you

Thanks and Regards,

Sarthak

Ankur Bawiskar
Tera Patron
Tera Patron

@NeethuB 

so my assumption is the above code is working fine and creating RITM but the incoming email has attachment and you want that to be copied to newly created RITM?

what's your use-case?

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

yes , can you provide any solution

@NeethuB 

So as per your information the RITM is getting created and the incoming file to email should get copied to RITM

please update code as this

var ritm=new GlideRecord("sc_req_item");
    ritm.addQuery('request',rc.sys_id);
    ritm.query();
    if(ritm.next())
    {
        ritm.short_description = email.subject.toString();
        ritm.contact_type="email";
        ritm.update();
new GlideSysAttachment().copy('sys_email', sys_email.sys_id, 'sc_req_item', ritm.sys_id);
    }

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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