Attachment is attached to the attachement section in workspace how email has sent to notify the user

mania
Tera Contributor

Hi,

 

Once attachment is attached to the attachement section in workspace how email has sent to notify the user.

 

Can anyone help on this, It will be helpfull.

 

Thanks!

2 REPLIES 2

Robbie
Kilo Patron
Kilo Patron

Hi @mania,

 

Take a look at the following post which covers this quite extensively.

 

To help others (or for me to help you more directly), please mark this response correct by clicking on Accept as Solution and/or Kudos.


Thanks, Robbie

 

https://www.servicenow.com/community/developer-forum/how-to-trigger-mail-whenever-attachment-is-adde...

Yashsvi
Kilo Sage

Hi @mania,

To notify a user via email when an attachment is added to a record in ServiceNow Workspace, you can use a combination of Business Rules, Script Includes, and Notification records.

Create a Business Rule on the Attachment Table

1. Navigate to 'System Definition > Business Rules'
2. Create a New Business Rule:
- Name: Notify User on Attachment Add
- Table: Attachment [sys_attachment]
- When: After Insert
- Advanced: Checked
3. Script:

 (function executeRule(current, previous /*null when async*/) {
       var parentRecord = new GlideRecord(current.table_name);
       if (parentRecord.get(current.table_sys_id)) {
           var recipientEmail = parentRecord.getValue('assigned_to.email');
           if (recipientEmail) {
               gs.eventQueue('attachment.added.notify', parentRecord, recipientEmail, current.sys_id);
           }
       }
   })(current, previous);

Create a Notification

1. Navigate to 'System Notification > Email > Notifications'
2. Create a New Notification:
- Name: Notify User on Attachment Add
- Table: [Parent record table, e.g., Incident]
- When to Send: Event is Fired: 'attachment.added.notify'
- Send To: Users/Groups in Fields: 'Assigned to'
3. Email Content:
- Subject:Attachment Added to Record
- Message:

 <p>An attachment has been added to the record <b>${number}</b>.</p>

Conclusion:
1. Business Rule: Triggers when an attachment is added and queues an event.
2. Notification: Listens for the event and sends an email to the user specified in the `Assigned to` field.

This setup ensures that users are notified via email whenever an attachment is added to a record.

 

Thank you, please make helpful if you accept the solution.