Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Why notification is not getting send?

Prathamesh Cha1
Tera Contributor

Hi all, 

 

I want to send notification whenever the hr case is getting updated but I dont know why its not working

upto 

"gs.addInfoMessage(gc.opened_for.getDisplayValue())" my code is working fine but event is not getting triggered and notification is not getting send
Actually in question answer table many dates are there and I am subtracting 14 days from every date and I am trying to match it with todays and if gets match then I am trying to send notification
BR is in Human resource core application
conds are whenever hr case getting updated
and I am going tO PUT that code in scheduled job to run it daily basis please check
 
(function executeRule(current, previous /*null when async*/) {

    // Add your code here
    var ed = '';
var gr = new GlideRecord('question_answer');
gr.addEncodedQuery('question.question_textSTARTSWITHexpected target date^sys_created_onONThis week@javascript:gs.beginningOfThisWeek()@javascript:gs.endOfThisWeek()')
gr.query()
while(gr.next())
{
     ed = gr.value
    var gdt = new GlideDateTime(ed);
     gdt.getDate();
     gdt.addDaysUTC(-14)
    var td = new GlideDate();
    if(gdt.getDate().getDisplayValue()==td.getDisplayValue()){
         var hrcase = gr.table_sys_id;
         var gc = new GlideRecord('sn_hr_core_case');
         gc.addQuery('sys_id', hrcase);
         gc.query();
         while(gc.next())
         {
            gs.addInfoMessage(gc.opened_for.getDisplayValue())
            gs.eventQueue('sn_hr_core.trigger_two_weeks_before_orgc',gr,gc.opened_for,null);
         }
  }



}


})(current, previous);
 
PrathameshCha1_0-1698753141834.png

 

event

PrathameshCha1_1-1698753182091.png

notification

PrathameshCha1_2-1698753216891.png

 

2 REPLIES 2

-O-
Kilo Patron

It seems to me you are providing the wrong parameters to gs.eventQueue(): in the last picture event sn_hr_core.trigger_two_weeks_before_orgc is shown as defined for table sn_hr_core_case, but you are passing in gr as 2nd parameter; however on line 5gr is defined for table question_answer.

It should be:

 

gs.eventQueue('sn_hr_core.trigger_two_weeks_before_orgc', gc, gc.opened_for, null);

 

Next time you decide to take no. 2 on spacing, formatting, variable naming and (not) using functions, remember the words of John F. Woods. 😄

Tai Vu
Kilo Patron
Kilo Patron

Hi @Prathamesh Cha1 

 

You're passing the object gr (question_answser) while the event was defined in the sn_hr_core_case table.

Let's correct it to gc (sn_hr_core_case) instead.

 

If it still doesn't work, let's try to have a look into the Event Queue.

URL: https://<instance_name>/sysevent_list.do?sysparm_query=nameSTARTSWITHsn_hr_core.trigger_two_weeks_be...

 

You can also access record producer variables by using <GlideRecord>.variables.<variable_name>.

 

 

Cheers,

Tai Vu