How to trigger notification, it contains multiple records?

prasanna7869
Mega Expert

Hi Team,

I have requirement on email notification.

Based on Requestor, we need to trigger notification for each quarter and should show multiple records. How can we achieve this requirement?

For example, when gliding the table with one "quarter" duration, the following records are displayed:

INC001234 - Requestor A

INC002345 - Requestor B

INC004567 - Requestor A

INC002367 - Requestor A

INC004523 - Requestor A

INC005678 - Requestor B

So, I want to send a notification to Requestor A like following way:

------------------------------------------------------

Hi Requestor A,

The following records for this Quarter:

INC001234

INC004567

INC002367

INC004523

Thanks,

Team

------------------------------------------------

Requestor B like following way:

------------------------------------------------------

Hi Requestor A,

The following records for this Quarter:

INC002345

INC005678

Thanks,

Team

------------------------------------------------

I tried the following way:

var gr = new GlideRecord('incident');

gr.addQuery('u_status','u_active');

gr.query();

if(gr.next()){

var creDate = gr.sys_created_on;

var expDate = gs.now();

var diff = gs.dateDiff(creDate,expDate,true);

                  if(diff>=7344000 && diff<=7776000)                               // I've taken 85 and 86 days records

                  {

                    gs.print(gr.u_number+ '- ' gr.u_requestor);

                  }

}

By this script, I'm getting out put like:

INC001234 - Requestor A

INC002345 - Requestor B

INC004567 - Requestor A

INC002367 - Requestor A

INC004523 - Requestor A

INC005678 - Requestor B

Now I need to send a notification to Requestors A & B. I know by using gs.eventQueue we can send notification. But, my query is how can we separate requestors records and how can we send the same.

Please suggest solution ASAP.

Thanks & Regards,

Prasanna Kumar

12 REPLIES 12

Did you check to see if there is an event triggered for each recipient? Also, try the scheduled job script in scripts background to ensure the array contains the values you want. This should help debug to ensure you are triggering the right notifications:



Faster Server Side Script Development and Test


Yes Tomasi,



I checked Event logs, and how many SYS_ID's are generating when event triggered. But, the notification triggers only one person and that to all the output requestors notification field is enable.



So, I want to show the following filter for all the requestors:



Requestor is ME


&


number is one of Javascript: BackfillAssignmentGroup().loadCWRRecords();



So, for this I written following code for getting records:



loadCWRRecords: function() {



  var cwrParentqual = '';


  var cwrReq = gs.getUserID();


  var cwrgr = new GlideRecord('u_contingent_worker_on_board_form');


  cwrgr.addQuery('u_requestor',cwrReq);


  cwrgr.query();


  //cwrParentqual = 'u_status=u_active^sys_idIN';


  cwrParentqual = '';


  if(cwrgr.next()) {


  var creDate1 = cwrgr.sys_created_on;


  var expDate1 = gs.now();


  var diff = gs.dateDiff(creDate1,expDate1,true);


  if(diff>=7344000 && diff<=7776000){


  cwrParentqual = cwrgr.u_number.toString();gs.log("$$$786900 records one"+cwrParentqual);


  }



  }


  while(cwrgr.next()) {


  var creDate2 = cwrgr.sys_created_on;


  var expDate2 = gs.now();


  var diff2 = gs.dateDiff(creDate2,expDate2,true);


  if(diff2>=7344000 && diff2<=7776000){


  cwrParentqual += ',' + cwrgr.u_number.toString(); gs.log("$$$786900 records"+cwrParentqual);


  }



  }



  return cwrParentqual;


},



But it is not showing the records in list layout.



Please check and let me know if any issues in the script.



Thanks & Regards,


Prasanna Kumar


I don't see anything outright that would cause the script to have any issues that you describe. Continue to debug using scripts background (or Xplore from the share portal) as your debugging workbench.


Hi Prasanna,


Did you solve this issue.?


I used this for the CAB reminder emails and it works great, thank you.