Trigger notification when record is deleted from table

lavu
Kilo Contributor

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,

1 ACCEPTED SOLUTION

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

View solution in original post

13 REPLIES 13

Hi Sachin. 

as created everything as suggested about , but no luck ,, email is not getting triggered.

gs.eventQueue('dabaseaccess.update1',current,current.u_access_description,'');  

this is how am passsing the even queue

 

 

 

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

Hi Sachin,

Thank you so much for the quick response:)

it works as expected

Thanks a lot:)

Bhagyashri Sort
Kilo Guru

Hi,

You can write a before or after business rule to trigger a notification on deletion of record.

Here you can refer the following links :

https://community.servicenow.com/community?id=community_question&sys_id=47e4472ddbd8dbc01dcaf3231f96...

 

https://community.servicenow.com/community?id=community_blog&sys_id=2d6dea29dbd0dbc01dcaf3231f961956 

 

Make it Correct or mark it helpful, if my response helps you.

 

   Thanks

Bhagyashri Sorte

 

Indrajit
Mega Guru

Hey lavu,

Create an after delete business rule

Create an event on the table

Create an email notification on that table and associate the event with this email

fire the event from the BR and set the recipient

find_real_file.png

find_real_file.png

in Notification

find_real_file.png

In Event registry

find_real_file.png

you can refer this thread as well,

https://community.servicenow.com/community?id=community_question&sys_id=47e4472ddbd8dbc01dcaf3231f96...

mark Correct and Helpful if applicable.

Regards,

Indrajit.