- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2020 05:24 AM
Hi Team,
Can someone help me how to trigger notification when record is deleted from table???
the notification should contain details of the deleted record also.
any help would be appreciated,
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-04-2020 12:43 AM
Hi,
I realized that we shouldn't use the 'current' object in gs.event method, since before the event triggers that record is getting deleted and so current object not holds any data about record.
Please follow the below, I have tested it in my personal instance and working fine.
- We need to set all required record details in a json object, and use that object in event parm1 field.
- We need to create notification mail script to extract the field details from even
- Add the mailscript in your notification template.
In Before Delete BR wirte code as below
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var obj ={
"number":current.number.toString(),
"shortDescription": current.short_description.toString()
};
var content = JSON.stringify(obj);
gs.eventQueue('record.inc.delete',null,content,'','');
})(current, previous);
Create Notification mail script as below.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
// Add your code here
var jsonObject = JSON.parse(event.parm1);
template.print('Incident Number: '+ jsonObject.number);
template.print('Incident ShortDescription: '+ jsonObject.shortDescription);
})(current, template, email, email_action, event);
Add the mail script in Notification template as below.
${mail_script:delete_record_content}
please mark it correct/helpful, if it answers your query,
Regards,
Sachin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2020 06:49 AM
Hi all,
eventhough the notification triggerd, it will not contain the details of deleted record.
can any onehelp me with this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-03-2020 07:10 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2022 12:42 AM
I have similar requirement to trigger notification when CI is deleted with CI Name, Date Deleted, Who Deleted & CI Class.
I have followed the procedure you have mentioned. The event is fired and processed with table as empty but the notification is not getting triggered.
1. Created before delete BR for table Configuration Item[cmdb_ci]
(function executeRule(current, previous /*null when async*/ ) {
var obj = {
"ci": current.name.toString(),
"date_deleted": gs.nowDateTime().toString(),
"who_deleted": gs.getUserDisplayName().toString(),
"ci_class": current.sys_class_name.toString()
};
var content = JSON.stringify(obj);
gs.eventQueue('cmdb_ci.delete.notification',null, content,'emailid@email.com');
})(current, previous);
2. Created event 'cmdb_ci.delete.notification' with table as none
3. Created Notification 'Send notification when CI is deleted' again table as 'none'
4. Created email template 'CI_delete.template' again table as 'none' and the mail script '${mail_script:when_ci_deleted}'
5. Created email script 'when_ci_deleted'
(function runMailScript(current, template, email, email_action, event) {
var jsonObject = JSON.parse(event.parm1);
template.print('<p class="template_header">CI has been deleted from the CMDB</p>');
template.print('<table class="template_TBL"><tbody>');
template.print('<tr><td class="firstCol">CI Name:</td><td>'+ jsonObject.ci +'</td></tr>');
template.print('<tr><td class="firstCol">Date Deleted:</td><td>'+ jsonObject.date_deleted +'</td></tr>');
template.print('<tr><td class="firstCol">Who Deleted:</td><td>' + jsonObject.who_deleted + '</td></tr>');
template.print('<tr><td class="firstCol">CI Class:</td><td>' + jsonObject.ci_class + '</td></tr>');
template.print('</tbody></table>');
email.setSubject(jsonObject.ci + " has been deleted from the CMDB");
})(current, template, email, email_action, event);
Could you please help me as why the notification is not getting triggered.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2024 10:40 AM
Hi ameersuhail,
Facing a similar issue. Were you able to resolve this?