Need to trigger notification based on schedule job but event log status showing error

mani55
Tera Contributor

Based on schedule job i need to trigger notification but present event is triggered but event status showing error and notification is not triggered so please let me know the mistake.

 

schedule script:

 

var currentMonth = new GlideDateTime().getMonth(); // Get the current month (0-11)

// Check if the current month is July (6) or November (10)
if (currentMonth == 6 || currentMonth == 12) {
    var risk = new GlideAggregate('u_transversal_code');
risk.groupBy('u_user');
risk.query();
while (risk.next()) {
	var created_by = new GlideRecord("sys_user");
	created_by.addQuery('sys_id',risk.u_user.sys_id);
	created_by.query();
	if(created_by.next()){	
        gs.eventQueue('access_rights_renewal',risk,null,risk.u_user);
	}
	
}
    }

 

event :

 

mani55_0-1730783029286.png

Notification

 

mani55_1-1730783061458.png

 

1 ACCEPTED SOLUTION

Hello @mani55 

As @GlideFather  rightly pointed out, the event expects a GlideRecord object, which necessitated some modifications to the code. Here’s the updated script:

 

var risk = new GlideAggregate('u_transversal_code');
risk.addAggregate('COUNT');
risk.groupBy('u_user'); // Group by u_user to get unique users
risk.query();

while (risk.next()) {
    var created_by = new GlideRecord('sys_user');
    created_by.addQuery('sys_id', risk.getValue('u_user'));
    created_by.query();
    if (created_by.next()) {
        gs.eventQueue('access_rights_renewal', created_by, null, created_by.getValue('sys_id'));
    }
}

 

This revised code will trigger the event for each unique user and send notifications accordingly. This works in my PDI.

 

"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"

 

Thank You

Juhi Poddar

View solution in original post

9 REPLIES 9

Hello @mani55 

The provided code will trigger the event for 350 unique users only, as per your requirement. However, based on the screenshot, I can confirm that both the event class and event name are set correctly. Given this confirmation, we should consider the following factors to troubleshoot the error state in the Event table for the notification event:

  1. Configuration Issues:

    • Review the configuration settings for the notification. There may be misconfigurations regarding the intended recipients. Ensure that the correct user groups or individual users are specified.
    • Check the conditions for the notification to confirm that they are being met when the event is triggered.
  2. Scripting Errors:

    • Investigate any scripts associated with the notification. There could be logic errors or syntax issues that are preventing the notification from processing as intended.

"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"

 

Thank You

Juhi Poddar

It might be caused due to the "risk" part in your event, as it is GlideAggregate, and perhaps the event expect GlideRecord instead... 
For this, try to remove the GA from the Event, make it without any parameters as seen below and fire it to see what it does. And maybe also try to remove the table on the Event registry (keep it empty), then fire the event to see if it makes difference. 

 

 gs.eventQueue('access_rights_renewal', current, '', '');

 


Also, you are combining single and double quotes in your code but I do not expect that would be the problem

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


@GlideFather i used below scripting  and event table name i'll given as empty now event is triggered but notification not generated

 

mani55_0-1730798733665.png

var risk = new GlideAggregate('u_transversal_code');
risk.addAggregate('COUNT');
risk.groupBy('u_user'); // Group by u_user to get unique users
risk.query();

while (risk.next()) {
    var userId = risk.getValue('u_user'); // Get the unique user's sys_id
    if (userId) {
        //gs.eventQueue('access_rights_renewal', risk, null, userId); // Send the event only once per user

		gs.eventQueue('access_rights_renewal', current, '', '');
    }
}

 

 

Aha OK, then try to keep the table and re-trigger again with the event 2.0 as you have 


In my opinion the issue is caused by the usage of GlideAggregate for var risk, try to either switch GA to GlideRecord, or to skip it in the eventQueue();


EDIT: and also an event without the GlideAggregate but not empty, something like this:

gs.eventQueue('access_rights_renewal',current,current.number,gs.getUserName());

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Hello @mani55 

As @GlideFather  rightly pointed out, the event expects a GlideRecord object, which necessitated some modifications to the code. Here’s the updated script:

 

var risk = new GlideAggregate('u_transversal_code');
risk.addAggregate('COUNT');
risk.groupBy('u_user'); // Group by u_user to get unique users
risk.query();

while (risk.next()) {
    var created_by = new GlideRecord('sys_user');
    created_by.addQuery('sys_id', risk.getValue('u_user'));
    created_by.query();
    if (created_by.next()) {
        gs.eventQueue('access_rights_renewal', created_by, null, created_by.getValue('sys_id'));
    }
}

 

This revised code will trigger the event for each unique user and send notifications accordingly. This works in my PDI.

 

"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"

 

Thank You

Juhi Poddar