Trigger notification when attachment is added
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-06-2017 10:58 AM
I have seen several discussion on how to trigger a notification when an attachment is added. I recently researched this for a custom scoped application that I created for our internal business needs. The requirement was to send an email notification when the user adds an attachment to a request (custom table) they had previously submitted.
I found a more direct and less invasive solution than previously posted. This solution keeps the changes within the scoped application. I wrote this up as a design pattern... planning to keep a repository of these for future reference to ensure consistency of application development.
Creating a notification based on an attachment being added to a record of a custom table in a scoped application requires an extra jump.
Problem
The complexity of this notification comes from the fact that the attachments are added to the global table sys_attachment which also contains data per the relationship to the associated table and record (sys_id) to which the attachment belongs. Also, there is an out of box global event fired (attachment.uploaded) when the attachment is added. Unfortunately, when the notification on the custom table fires on this global event, the event contains reference the the sys_attachment record that was created, not the indirect custom table and custom table record to which it is associated.
Solution
Create a server-side script action and register a scope level event that:
- Catches the global attachment.uploaded event
- Extracts the attachment's associated table/record instance info
- Fires the scope level event with the customer table and record instance info
Usage
Luckily the global event attachment.uploaded has the following parameters we can use:
- parm1 = <custom table name> of the table to which the attachment was created
- parm2 = instance sys_id of the record in the <custom table name> to which the attachment is associatedThe notification on attachment add is setup via the following steps:
- Create a new event for the table for sending when the attachment is added
Suffix: "<table name - scope>.attachAdd"
Table: <table name> - Create a Server->ScriptAction:
Event name: attachment.uploaded
Condition script: event.parm1 = "<table name>"
Script like:
fireAttachmentEvent();
function fireAttachmentEvent()
{
// Send event for attachment added
gs.eventQueue("<table name>.attachAdd", event.parm1, event.parm2);
} - Create a Notification to fire on the new event:
Table: <table name>
Send when: Event is fired
Event name: "<table name>.attachAdd"
- 3,597 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2018 04:09 PM
This worked perfectly!
Thanks for the solution Thomas!
Cheers,
Pri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 12:31 PM
Do you have screen
shot ?