Send email with only newly added attachment for Network assignment group incidents

GaneshErike
Tera Expert

Hi Team,

 

I have a requirement to send an email notification when a new attachment is added to an Incident, but only for incidents assigned to the Network assignment group.

 

The email must include only the newly added attachment.

Previously attached / older attachments should NOT be included in the email.

 

Thanks in advance.

1 REPLY 1

Itallo Brandão
Tera Guru

Hi @GaneshErike ,

This is a specific requirement that cannot be met with standard Incident notifications because checking "Include Attachments" will always send all historical files.

To send ONLY the newly added file, you must trigger the Notification from the sys_attachment table context.

Here is the complete architectural solution, including Performance safeguards and Email Script requirements.



The Solution Design

  1. Trigger: An Async Business Rule on sys_attachment filters for Incidents assigned to "Network".

  2. Event: Fires with the specific Attachment record as current.

  3. Notification: Runs on sys_attachment and sends that single file.


Implementation Steps

1. Create the Event

  • Event Name: incident.network.attachment.added

  • Table: Attachment [sys_attachment]

  • Fired By: Business Rule

2. Create the Business Rule (Performance Optimized) We will use Async to ensure the user's file upload is not blocked, and strict Conditions to prevent performance impact on the busy Attachment table.

  • Name: Trigger Notification for Network Attachments

  • Table: Attachment [sys_attachment]

  • Advanced: true

  • When: Async (Insert)

  • Condition: Table name [IS] incident (Crucial: This ensures the script only loads for Incidents, ignoring all other system attachments).

Script:

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

    // 1. Fast Lookup (Primary Key)
    var grInc = new GlideRecord('incident');
    if (grInc.get(current.table_sys_id)) {
        
        // 2. Check Assignment Group
        // Recommendation: Use a System Property or SysID instead of hardcoding 'Network'
        if (grInc.assignment_group.getDisplayValue() == 'Network') {
            
            // 3. Fire the event
            // Parm1: Recipient (Group), Parm2: Incident Number
            gs.eventQueue('incident.network.attachment.added', current, grInc.getValue('assignment_group'), grInc.getValue('number'));
        }
    }

})(current, previous);

3. Create the Notification

  • Name: New Attachment Added (Network)

  • Table: Attachment [sys_attachment]

  • Send when: Event is fired (incident.network.attachment.added)

  • Who will receive: Check "Event parm 1 contains recipient".

⚠️ Critical Points of Attention

1. Variables will NOT work (Requires Mail Script) Since this notification runs on the sys_attachment table, standard variables like ${number} or ${short_description} will be empty. You must use a Notification Email Script to fetch Incident details.

  • Create Email Script: print_inc_details

    JavaScript
     
    (function runMailScript(current, template, email, email_action, event) {
        var grInc = new GlideRecord('incident');
        if (grInc.get(current.table_sys_id)) {
            template.print("Incident: " + grInc.getValue('number') + "<br/>");
            template.print("Summary: " + grInc.getValue('short_description'));
            // Add links as needed
        }
    })(current, template, email, email_action, event);
  • Usage in Body: ${mail_script:print_inc_details}

2. The "Spam" Risk (Multiple Files) Be aware: If a user drags and drops 5 files at once, this logic will trigger 5 separate emails. This is the trade-off for sending files individually.


If this comprehensive guide helps you implement the requirement safely, please mark it as Accepted Solution.

Best regards,
Brandão.