- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2016 06:10 AM
I'm trying to send an email notification to assignment group in incident task record when new/update attachment is added.
Any idea?
"Include Attachments" option sends only on the update in the incident record.
Any help on how to trigger an email notification when attachment alone added?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2016 08:05 PM
Hello Teju,
I have used a similar method for onboarding new users. Here is what I had to do.
I wanted new users on the project to upload required security documents. Once they uploaded documents, based on the conditions that their attachments that were uploaded to their profile contained the key words "HIPAA" and "DHS" would trigger an event (notice the event name that is created is "onboard.attachment").
off the event, an email notification and template would be shot out.
BR - User Form Attach Notify
var userrec = new GlideRecord("sys_user");
userrec.get(current.table_sys_id);
var today = new GlideDate;
var pattern = "HIPAA";
var result = current.file_name.match(pattern);
if (JSUtil.has(result) ) {
gs.log("filename " + current.file_name + " for user " + userrec.name + " contains " + pattern);
gs.eventQueue('onboard.attachment', current, gs.getUserDisplayName(), userrec.name);
}
else {
pattern = "DHS";
result = current.file_name.match(pattern);
if (JSUtil.has(result) ) {
gs.log("filename " + current.file_name + " for user " + userrec.name + " contains " + pattern);
gs.eventQueue('onboard.attachment', current, gs.getUserDisplayName(), userrec.name);
}
else gs.log("filename " + current.file_name + " for user " + userrec.name + " not matched to a pattern");
}
//gs.log("user " + userrec.name);
//if (userrec.sys_created_on > gs.daysAgo(30)) {
// gs.log(" new user " + userrec.name + ", created " + userrec.sys_created_on + " just attached file " + current.file_name );
//Queue the email send event
//Pass in event name, record(not applicable here), custom parm1, and custom parm2
//Custom parm1 is the count of incidents queried and can be referenced from the email notification that responds to the queued event by using '${event.parm1}' in the email notification record.
//gs.eventQueue('onboard.attachment', current, gs.getUserDisplayName(), userrec.name);
//gs.getUserName()
//}
//else gs.log(" old user attachment, created " + userrec.sys_created_on + " just attached file " + current.file_name );
The Email Notification that fires off the event named "onboard.attachment" and the email template associated with the email notification.
Now based on your request you were wanting to apply a similar situation to an incident. simply change the code that references the "sys_user" table in the GlideRecord to the incident table and the file names that are being searched for. You could also look at this old code we have when we were not searching attachments based on file names.
var userrec = new GlideRecord("sys_user");
- userrec.get(current.table_sys_id);
var today = new GlideDate;
- gs.log("user " + userrec.name);
if (userrec.sys_created_on > gs.daysAgo(14)) {
gs.log(" new user " + userrec.name + ", created " + userrec.sys_created_on + " just attached file " + current.file_name );
//Queue the email send event
//Pass in event name, record(not applicable here), custom parm1, and custom parm2
//Custom parm1 is the count of incidents queried and can be referenced from the email notification that responds to the queued event by using '${event.parm1}' in the email notification record.
- gs.eventQueue('onboard.attachment', current, gs.getUserDisplayName(), userrec.name);
//gs.getUserName()
}
else gs.log(" old user attachment, created " + userrec.sys_created_on + " just attached file " + current.file_name );
I hope this helps. Please let me know should you have any questions.
Sincerely,
Orlando Galindo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2016 09:24 AM
Here is the Business rules code (after insert or update):
checkAttachment();
function checkAttachment() {
var logged_user = gs.getUserDisplayName();
var addedfileLink ="[code]<a class='linked formlink' href='sys_attachment.do?sys_id="+current.sys_id+"'>" + "<font color='Green'><b> " +current.file_name+"</b></font></a><a target='_blank' class='linked formlink' href='sys_attachment.do?sys_id=" + current.sys_id + "&view=true'>" + " " + "[view]"+"</a>[/code]";
// if attach is deleted
if (current.operation() == 'delete') {
var task = new GlideRecord('task');
task.addQuery('sys_id', current.table_sys_id);
task.query();
if (task.next()) {
task.work_notes = "Attachment " + "[code]<font color='DarkRed'><b>" + current.file_name + "</b></font>[/code]" + " has been removed from this record by " + logged_user;
task.update();
}
}
// if attach is added
else if (current.operation() == 'insert') {
var task = new GlideRecord('task');
task.addQuery('sys_id', current.table_sys_id);
task.query();
if (task.next()) {
task.work_notes = "Attachment " + addedfileLink + " " + " has been inserted in this record by " + logged_user;
task.update();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2016 10:28 AM
Hi Mach,
Thanks for the code , I tried writing the same code for request task table but seems work notes are not getting updated
BR
Table : u_request_task
After Insert or update
function onAfter(current, previous) {
//This function will be automatically called when this rule is processed.
checkAttachment();
function checkAttachment() {
var logged_user = gs.getUserDisplayName();
var addedfileLink ="[code]<a class='linked formlink' href='sys_attachment.do?sys_id="+current.sys_id+"'>" + "<font color='Green'><b> " +current.file_name+"</b></font></a><a target='_blank' class='linked formlink' href='sys_attachment.do?sys_id=" + current.sys_id + "&view=true'>" + " " + "[view]"+"</a>[/code]";
// if attach is deleted
if (current.operation() == 'delete') {
var task = new GlideRecord('u_request_task');
task.addQuery('sys_id', current.table_sys_id);
task.query();
if (task.next()) {
task.work_notes = "Attachment " + "[code]<font color='DarkRed'><b>" + current.file_name + "</b></font>[/code]" + " has been removed from this record by " + logged_user;
task.update();
}
}
// if attach is added
else if (current.operation() == 'insert') {
var task1 = new GlideRecord('u_request_task');
task1.addQuery('sys_id', current.table_sys_id);
task1.query();
if (task1.next()) {
task1.work_notes = "Attachment " + addedfileLink + " " + " has been inserted in this record by " + logged_user;
task1.update();
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2016 12:34 PM
This one needs to run on the sys_attachment table and not run on insert / update, but insert / delete.
BR
Marc.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-01-2016 04:13 PM
yes above one is working when i changed to sys_attachment table. As of now we will go with this workaround. BUT needs to fixed directly notification should go when it is attached/modified.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2016 12:15 AM
I advise you raise a ticket with SNC on hi concerning the event issue.