- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 09:05 PM
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 :
Notification
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 02:07 AM - edited 11-05-2024 02:09 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 12:34 AM
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:
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.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 01:05 AM - edited 11-05-2024 01:05 AM
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! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 01:26 AM
@GlideFather i used below scripting and event table name i'll given as empty now event is triggered but notification not generated
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, '', '');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 01:28 AM - edited 11-05-2024 01:37 AM
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! */
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-05-2024 02:07 AM - edited 11-05-2024 02:09 AM
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