The CreatorCon Call for Content is officially open! Get started here.

Event Fired with Mail Notification

sukant
Kilo Contributor

Hi All,

I have an Requirement

Event:When the Additional comment section is updated before reaching the Finalized state.

Email Recipient:   Approvor (The email should have a link to the RITM.)

I want to set an event and trigger a mail to approver list   after updating the   Additional comment field in RITM Table.

Thanks

Sukant

4 REPLIES 4

tanumoy
Tera Guru

phillip_keigley
Kilo Contributor

1) Create event in event registry.   ( Go to System Policy | Registry   )  


Name: ritm_approver_email Table: sc_req_item  


2) Create a business rule that fires an event onChange of the comments field.


Name:BR-FireNotificationEventToApprover


Table: sc_req_item


Filter Condition: Additional Comments Changes and State is not Closed Complete, Closed Incomplete, Closed Skipped.


Tick the "Update" to indicate it should run on an update.


Script:


(function executeRule(current, previous /*null when async*/) {


var approver_array = [];


  var gr = new GlideRecord('sysapproval_approver');


  gr.addQuery('sysapproval', current.sys_id);


  gr.query();


  gs.log('count: ' + gr.getRowCount());


  while (gr.next()) {


  approver_array.push(gr.sys_id.toString());


  gs.log('what is approver array' + approver_array);


  }


  // Name of Event, Current Record, Parm 1, Parm 2.


  gs.eventQueue("ritm_approver_email", current, approver_array, approver_array);



})(current, previous);



3) Lastly, set up a notification that sends on an event, select event   ritm_approver_email.   For recipients of the email, select Parm 1 or Parm 2.   That will send to all approvers.  


Hi Phillip,



Thanks for sharing your solution.   It worked with the exception of the script on the business rule.   Here is my working code:



(function onAfter(current, previous /*null when async*/) {


var approver_array = [];


  var gr = new GlideRecord('sysapproval_approver');


  gr.addQuery('sysapproval', current.sys_id);


  gr.addQuery('state','=','requested');


  gr.query();


  gs.log('count: ' + gr.getRowCount());


  while (gr.next()) {


  approver_array.push(gr.approver.toString());   <--- I updated this line


  gs.log('what is approver array' + approver_array);


  }


  // Name of Event, Current Record, Parm 1, Parm 2.


  gs.eventQueue("ritm_approver_email", current, approver_array, approver_array);



})(current, previous);


terp
Giga Contributor

Hi Sukanta,



Goran wrote a blog on firing email notifications that should be helpful.     Check out his blog here.



https://community.servicenow.com/community/blogs/blog/2016/06/06/fire-an-email-notification-from-a-s...



Please mark this answer correct if it is helpful.  



Thanks.