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
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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Ankur Bawiskar
Tera Patron
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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi @Ankur Bawiskar ,

 

Thank you for reply.

I added the code in the inbound action. Still not getting attachment.

Samiksha2_0-1699520158045.png

This is email log. In the email log attachment is there but in the RITM it is not coping. 

 

Thanks,

Samiksha

Hi @Ankur Bawiskar ,

I search this article.
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0547763

I am not sure if this resolve my issue but how

 

Thanks,

Sam

@Samiksha2 

the line I shared should work fine.

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