business rule to fire event in custom scoped app

NeelyC
Tera Contributor

i am trying to fire my event from a business rule.

i need to send a message to the assignee when an additional comment (comments) field is updated by the caller. 

something isn't really working.

 

my business rule:

Screenshot 2025-07-21 at 17.04.24.png

 

(function executeRule(current, previous /*null when async*/ ) {
var caller = current.opened_by;
var assignTo = current.assigned_to;
var groupMng = current.assignment_group.manager;
 
if (current.updated_by == caller) {
var url = '<a href="/esc?sys_id=' + current.sys_id + '&view=portal&id=ticket&table=x_1776226_mobile_1_custom_mobile_issues">' + current.number + '</a>';
if (assignTo)
gs.eventQueue('x_1776226_mobile_1.add_comm_by_caller', current, assignTo, url);
else
gs.eventQueue('x_1776226_mobile_1.add_comm_by_caller', current, groupMng, url);
// }
})(current, previous);
 
 
 
my event:
 Screenshot 2025-07-21 at 17.10.07.png

 my notification:

Screenshot 2025-07-21 at 17.11.18.png

Screenshot 2025-07-21 at 17.11.25.png

 i would much appreciate your help

1 ACCEPTED SOLUTION

@NeelyC 

why it wouldn't trigger if comments are added via employee center?

I don't think it will stop triggering.

It's a record update and if condition matches it will send email

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Chaitanya ILCR
Mega Patron

Hi @NeelyC ,

 

you didn't select the table name in the notification and the event registry record

 

select the table and try

 

also add few logs in the BR I have added 2 ( check the values of opened_by and updated_by)

 

is updated_by a reference field? as opened by? else use the last script 

check if you are getting the logs

 

 (function executeRule(current, previous /*null when async*/ ) {
     var caller = current.opened_by;
     var assignTo = current.assigned_to;
     var groupMng = current.assignment_group.manager;
     gs.info(' Test caller ' + caller + ' updated by ' + current.updated_by); 

     if (current.updated_by == caller) {
         gs.info(' Test inside if');
         var url = '<a href="/esc?sys_id=' + current.sys_id + '&view=portal&id=ticket&table=x_1776226_mobile_1_custom_mobile_issues">' + current.number + '</a>';
         if (assignTo)
             gs.eventQueue('x_1776226_mobile_1.add_comm_by_caller', current, assignTo, url);
         else
             gs.eventQueue('x_1776226_mobile_1.add_comm_by_caller', current, groupMng, url);
     }
 })(current, previous);


By updated_by are you referring to sys_updated_by or do you have a separate field updated_by?

if it's sys_updated_by please update the script as 

 

 (function executeRule(current, previous /*null when async*/ ) {
     var caller = current.opened_by;
     var updatedBy = current.sys_updated_by;
     var assignTo = current.assigned_to;
     var groupMng = current.assignment_group.manager;
     gs.info(' Test caller ' + caller + ' updated by ' + updatedBy);

     if (updatedBy == caller.user_name) {
         gs.info(' Test inside if');
         var url = '<a href="/esc?sys_id=' + current.sys_id + '&view=portal&id=ticket&table=x_1776226_mobile_1_custom_mobile_issues">' + current.number + '</a>';
         if (assignTo)
             gs.eventQueue('x_1776226_mobile_1.add_comm_by_caller', current, assignTo, url);
         else
             gs.eventQueue('x_1776226_mobile_1.add_comm_by_caller', current, groupMng, url);
     }
 })(current, previous);

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

hello,

thank you for the quick reply. 

 

i tried with and without, neither is fiering my event. 

comments are being added via activity stream from Employee Center

 

Hi @NeelyC ,

 

add logs and check 
I have edited the my last post please check

 

 

Please mark my answer as helpful/correct if it resolves your query.

Regards,
Chaitanya

SumanthDosapati
Mega Sage
Mega Sage

@NeelyC 

Did you add logs in BR and notification to see where is it broken?

 

Regards,
Sumanth