We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Attachment is not getting attach in the requested item when it is creating via inbound action

Samiksha2
Mega Sage

Hi,

I have created a inbound action to create Request and requested item. Whenever user is attaching any document with email it is not attaching in the respective requested item or request.

I checked the email logs. target is coming as blank.

 

This is inbound action on Request Table

var cartID = GlideGuid.generate(null);
    var cart = new Cart(cartID);
    var item = cart.addItem('562790589388b11034dbbb2c5cba');

    cart.setVariable(item, 'short_description', email.subject);
    cart.setVariable(item, 'description', email.body_html);
    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;
        ritm.description = email.body_html;
        ritm.comments = email.body_text;
		
        ritm.contact_type = "email";
  
        ritm.approval = "No Longer Required";
ritm.state = "Work in Progress";
        ritm.requested_for = gs.getUserID();
	

     
      
           
            
        
        ritm.update();
    }

 

Please help in this.

 

Thanks,

Samiksha

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@Samiksha2 

update and add this line

var cartID = GlideGuid.generate(null);
var cart = new Cart(cartID);
var item = cart.addItem('562790589388b11034dbbb2c5cba');

cart.setVariable(item, 'short_description', email.subject);
cart.setVariable(item, 'description', email.body_html);
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;
ritm.description = email.body_html;
ritm.comments = email.body_text;

ritm.contact_type = "email";

ritm.approval = "No Longer Required";
ritm.state = "Work in Progress";
ritm.requested_for = gs.getUserID();

ritm.update();

// to copy file to REQ use this

GlideSysAttachment.copy('sys_email',sys_email.getUniqueValue(),'sc_request',rc.sys_id.toString());

 

// to copy file to RITM use this

GlideSysAttachment.copy('sys_email',sys_email.getUniqueValue(),'sc_req_item',ritm.sys_id.toString());


}

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

7 REPLIES 7

Hi @Ankur Bawiskar ,

I tested with both code . Attachment is not getting copied to either Request or Requested Item.

 

Thanks,

Sam 

Hi @Ankur Bawiskar ,

 

It is working. Thanks. You always save me.😁
Actually there was a issue in the inbound actions.
Thanks,

Sam

@Samiksha2 

Glad to help.

Happy learning.

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