Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Can we attach email as attachment?

Mahesh Eethakot
Tera Contributor

Hello,

We automatically create Incidents from Google Cloud (GCP) alerts using Flow Designer. The alert details are currently placed in the Incident’s Description.
New requirement: preserve the full, original alert by attaching it to the Incident:
If the alert arrives by email: attach the original email to the Incident.

Thanks

3 REPLIES 3

Mahesh Eethakot
Tera Contributor

Step 1:

Copy attachments to incident auomatically based on field change and use the below code

(function executeRule(current, previous) {
   
    // Define your attachment sys_ids here
    var attachmentsToCopy = [
        'ec703852831132103c26caffeeaad39f',
        '0e817856831132103c26caffeeaad35b',
        'dbf1f896831132103c26caffeeaad34a',
        '7932f896831132103c26caffeeaad34d'
    ];
   
    // Copy each attachment
    for (var i = 0; i < attachmentsToCopy.length; i++) {
        var grSysAtt = new GlideRecord('sys_attachment');
        if (grSysAtt.get(attachmentsToCopy[i])) {
            var content = new GlideSysAttachment().getContentStream(grSysAtt.sys_id);
            new GlideSysAttachment().writeContentStream(
                current,
                grSysAtt.getValue('file_name'),
                grSysAtt.getValue('content_type'),
                content
            );
        }
    }
   
})(current, previous);

Step 2:

Copy attachments from that incident to email client template and below code

(function executeRule(current, previous /*null when async*/) {

    // Add your code here

    GlideSysAttachment.copy(current.target_table,  current.instance ,'sys_email', current.sys_id);


})(current, previous);

edward_williams
Tera Expert

The Incident IS the full original alert. You don't need to attach an email to an Incident. Mature your Incident alert so that it better represents the failure.