- 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-04-2024 09:36 PM
Hi @mani55
On which table the event "access_rights_renewal" is created, if it is on "u_transversal_code", then you have too pass the GlideRecord object of this table but in your script you are passing a GlideAggregate object.
Thanks and Regards,
Saurabh Gupta
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 10:11 PM
@Saurabh Gupta i used below scripting in background script for testing now it's working fine but one bug is there u_transversal_code in this table we have total 26000 records but when group by user field we have only 350 users so we need to send notification only 350 users but now it's triggered 26000 records
var risk = new GlideRecord('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);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2024 11:34 PM
Hello @mani55
Please try the below code:
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
}
}
"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-04-2024 11:41 PM
it's not working event logs state is showing error