Add attachment to notification

DebbyDebby
Tera Expert

I would like to add an attachment to notification after the catalog task is closed. The notification is working but it is not capturing the attachment. 

 

Note: The attachment field is one of the catalog variables, not the default attachment field

1 ACCEPTED SOLUTION

DebbyDebby
Tera Expert

I have figured it out. In workflow studio, i used 'Get variables' action to get the variable that has the attachment and use copy attachment action to copy it to the catalog task and finally used send notification action to send the attachment with the notification that i already created (I checked the 'include attachment' box in the notification). This works perfectly for me

View solution in original post

6 REPLIES 6

sago45
Tera Contributor

Hi,

You can try the GlideSysAttachment copy method. 

This page has a lot of information about it:

https://www.servicenow.com/community/now-platform-blog/sending-physical-attachments-on-outbound-emai...

dgarad
Giga Sage

Hi @DebbyDebby 

 Refer the below link.

https://www.servicenow.com/community/developer-forum/create-a-incident-record-when-incident-state-ch...

If my answer finds you well, helpful, and related to the question asked. Please mark it as correct and helpful.

Thanks
dgarad

Runjay Patel
Giga Sage

Hi @DebbyDebby ,

 

Use below script to attach the attachment from catalog variable.

// Get the task's parent request item (RITM)
var ritmGR = new GlideRecord('sc_req_item');
if (ritmGR.get(current.request_item)) { // Assuming 'request_item' links the task to the RITM

    // Query the sc_item_option_mtom table to fetch the attachment variable
    var varMtomGR = new GlideRecord('sc_item_option_mtom');
    varMtomGR.addQuery('request_item', ritmGR.sys_id);
    varMtomGR.addQuery('sc_item_option.value', 'CONTAINS', 'sys_attachment'); // Ensure it's an attachment
    varMtomGR.query();
    
    while (varMtomGR.next()) {
        // Get the sys_id of the attachment
        var attachmentGR = new GlideRecord('sys_attachment');
        attachmentGR.addQuery('table_sys_id', varMtomGR.sc_item_option.value); // Link the attachment to the RITM
        attachmentGR.query();

        while (attachmentGR.next()) {
            // Attach the file to the notification
            notification.addAttachment(attachmentGR);
        }
    }
}

 

-------------------------------------------------------------------------

If you found my response helpful, please consider selecting "Accept as Solution" and marking it as "Helpful." This not only supports me but also benefits the community.


Regards
Runjay Patel - ServiceNow Solution Architect
YouTube: https://www.youtube.com/@RunjayP
LinkedIn: https://www.linkedin.com/in/runjay

-------------------------------------------------------------------------

DebbyDebby
Tera Expert

It is an sc_task and it is created through a workflow so the attachment is from a specific sc_task generated for a workflow.