Attachment for approval email notification from catalog task

jreddy7
Tera Contributor

Requirement:
There requset called Wan connection once requested request item generated in that catalog task generated for this catalog task 1 user attache draft form 20 closes the task once task 1 closed then catalog task 2 generates there user will attach the final form 20 and also attach approval email then closes the task now in request item approval will go now i want here one approval email notification should send to apporvers and also need attached the final form 20 which is attached in catalog task 2 which extension.pdf then in email notification i want to show approve and reject buttons

4 REPLIES 4

Mark Manders
Tera Patron

Can you ask your question again with punctuation, so we can read what it is exactly you are asking?

Ankur Bawiskar
Tera Patron

@Ankur Bawiskar I like this response 😄

Tanushree Maiti
Tera Patron

Hi @jreddy7 

 

1. Use the built-in Copy Attachment action to copy attachments from the Catalog Task to the RITM upon the task closure

  • If it is WF/BR, Check for script

GlideSysAttachment.copy('sc_task', current.getUniqueValue(), 'sc_req_item', current.request_item.getUniqueValue());

: https://www.servicenow.com/community/servicenow-impact-forum/copy-attachment-from-sc-task-to-ritm/m-...

https://www.servicenow.com/community/developer-forum/attachment-in-approval-notification/m-p/1465852

 

  1. Create an Email Notification Script for the .pdf

You can retrieve and attach the Form 20.pdf using an Email Script

  • Navigate to System Policy > Email > Notification Email Scripts and click New.
  • Name it: include_final_form

 

(function runMailScript(current, template, email, event, email_action) {

    var grAttach = new GlideRecord('sys_attachment');

    grAttach.addQuery('table_sys_id', current.sysapproval.sys_id);

    grAttach.addQuery('table_name', 'sc_req_item');

    grAttach.addQuery('file_name', 'CONTAINS', '.pdf');

    grAttach.orderByDesc('sys_created_on');

    grAttach.query();

   

    if (grAttach.next()) {

        template.print('Attachment: <a href="sys_attachment.do?sys_id=' + grAttach.sys_id + '">' + grAttach.file_name + '</a>\n');

        email.addAttachment(grAttach.getValue('sys_id'));

    }

})(current, template, email, event, email_action);

 

3: Create the Approval Notification

  • Navigate to System Notification > Email > Notifications and click New.
  • Set Table to Approval [sys_approval_approver].
  • Under the When to receive tab, set the condition to trigger when State changes to Requested.
  • Under the What it will contain tab, invoke your script in the message body using ${mail_script:include_final_form}.