How to copy RITM attachment to the Approval notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2023 01:41 PM
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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2023 07:56 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-28-2023 06:49 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2023 09:38 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-27-2023 10:38 PM
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