Assistance Required: Notification to Approver with Business Rule

Mark Wood
Tera Contributor

Hello Team,

I am trying to send a notification to the approver 2 minutes after the approval record is created (just for testing purposes). In the actual use case, the notification should be sent 1 day after creation, and if the next day is a Saturday or Sunday, the notification should go out on the next working day.

I have implemented this logic using a Business Rule, but I'm encountering an issue:
The script fails to retrieve the approval record. The getRowCount() in gs.log always returns 0, even though the record exists.

However, when I run the same code in a background script, it works perfectly and retrieves the record.

I have pasted my Business Rule script below. Could you please help me identify what might be going wrong?

Thank you for your support.

 

(function executeRule(current, previous /*null when async*/ ) {
    var sysID = current.sys_id;
	
    var gdt = new GlideDateTime(current.sys_created_on);
    gdt.addSeconds(90);

    var gra = new GlideRecord('sc_req_item');

    var checkStatus = new GlideRecord('sysapproval_approver');
	checkStatus.addEncodedQuery('state=requested^source_tableSTARTSWITHsc_req_item^sysapproval.sys_id=' + sysID);
    checkStatus.query();
    gs.log("RowCountNew" + checkStatus.getRowCount());
   
    while (checkStatus.next()) 
	{
        gs.log("Recall Function block if");
        var grSchedule = new GlideRecord('cmn_schedule');
        grSchedule.addQuery('sys_id', '1b5bc5f3833d2210c287ac80ceaad30a'); //working scheudke sys_id
        grSchedule.query();

        if (grSchedule.next()) {
            var schedule = new GlideSchedule(grSchedule.sys_id);

            gs.log("Scheduled");
            while (!schedule.isInSchedule(gdt)) {
                // gdt.addDaysLocalTime(1);
                gs.log("Not Scheduled");
                gdt.addSeconds(60);


            }
            gs.eventQueueScheduled("notify.approver", current, "param1", "param2", gdt);
          

        }
    }
    



})(current, previous);
2 REPLIES 2

Anil Nemmikanti
Giga Guru

Hi @Mark Wood ,

In the Background script you might be giving the  static sys_id of the record. But in the BR it is dynamic.
Did you check what exactly current.sys_id is returning.

Hello @Anil Nemmikanti,

I am dynamically passing the sys_id in the background. I am retrieving all active record sys_ids one by one and printing the row count.

Thank you.