How to copy RITM attachment to the Approval notification

chrish5
Giga Guru

Hi Community,

I’m using the below Inbound Action script to create a request item and copy the attachment from the email that triggered it to the RITM.  The problem I am having is the approval email (sysapproval_approver table) that is generated from the request does not include this attachment from the RITM even though the “Include Attachment” is checked on the approval notification that is sent.  Can someone tell me how I get the attachment on the RITM on the approval notification?    Thanks!

 

createRequest();

function createRequest() {

var cart = new Cart();

// Add in cart, sys_id for MDF Monthly Door Access Audit Report catalot item

var item = cart.addItem('d9a69b671b1b611092beea40604bcbda');

// add cart message to commments

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

// Set date_needed variable to 5 days ahead of current date

var gdt = new GlideDateTime();

cart.setVariable(item,'short_description', "MDF door access audit");

// Places order and creates request

var rc = cart.placeOrder();

var ritm= new GlideRecord('sc_req_item');

ritm.addQuery('request',rc.sys_id);

ritm.query();

while(ritm.next()){

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

  }

}

6 REPLIES 6

Community Alums
Not applicable

Hi,

 

The issue with your code is that you are not copying the attachment to the sysapproval_approver table. You are only copying the attachment to the sc_req_item table.

To fix this, you need to add a line of code to copy the attachment to the sysapproval_approver table. The following code will do this:

 

createRequest();

function createRequest() {

var cart = new Cart();

// Add in cart, sys_id for MDF Monthly Door Access Audit Report catalot item

var item = cart.addItem('d9a69b671b1b611092beea40604bcbda');

// add cart message to commments

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

// Set date_needed variable to 5 days ahead of current date

var gdt = new GlideDateTime();

cart.setVariable(item,'short_description', "MDF door access audit");

// Places order and creates request

var rc = cart.placeOrder();

var ritm= new GlideRecord('sc_req_item');

ritm.addQuery('request',rc.sys_id);

ritm.query();

while(ritm.next()){

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

GlideSysAttachment.copy('sys_email', sys_email.sys_id, 'sysapproval_approver', rc.sys_id);

  }

}

 

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

 

Regards,

Kaustubh Kulkarni

Hi Kaustubh,  

Thank you for your response.  Unfortunately, adding that line of code did not copy the attachment to the approval emails that were sent to the approval group.  Any other thoughts on this? 

I ended up putting an async before business rule in place with the below script to copy the attachments from the RITM to the approval notifications.  

 

GlideSysAttachment.copy('sc_req_item', current.sysapproval.sys_id, 'sysapproval_approver', current.sys_id);

Amit Gujarathi
Giga Sage
Giga Sage

HI @chrish5 ,
I trust you are doing great.
To include the attachment from the RITM (Requested Item) in the approval notification, you can modify the existing script. Here's an updated version of the script:

createRequest();

function createRequest() {
  var cart = new Cart();
  
  // Add the sys_id for the MDF Monthly Door Access Audit Report catalog item to the cart
  var item = cart.addItem('d9a69b671b1b611092beea40604bcbda');
  
  // Add a cart message to comments, including the email details
  var cartMsg = "Received from: " + email.origemail + "\n\n" + email.body_text;
  
  // Set the date_needed variable to 5 days ahead of the current date
  var gdt = new GlideDateTime();
  
  // Set the short_description variable for the RITM
  cart.setVariable(item, 'short_description', "MDF door access audit");
  
  // Places the order and creates the request
  var rc = cart.placeOrder();
  
  // Retrieve the RITM records associated with the request
  var ritm = new GlideRecord('sc_req_item');
  ritm.addQuery('request', rc.sys_id);
  ritm.query();
  
  // Copy the attachment from the email to each RITM
  while (ritm.next()) {
    GlideSysAttachment.copy('sys_email', sys_email.sys_id, 'sc_req_item', ritm.sys_id);
  }
}

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi