Same license name is getting popped everytime when I trigger the notification
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 04:09 AM
Whenever the end date of a license in my alm_license table is 10 days away to get expire , it should send a notification to a particular group. For this I created
1.Schedule Job
2.Event
3.Notification
Whenever I am running this script in background script its working fine , but when I am running the scheduled job , it is triggering a notification but with a same license name everytime and that license end date is not even near to expiration.
Can anyone check why I am getting always the same license on the notification
Schedule Job
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-10-2025 04:17 AM - edited 03-10-2025 04:18 AM
The issue you're experiencing is likely due to the placement of the gs.eventQueue() function outside of the while (gr.next()) loop. When the loop finishes, the gr object will still hold the values of the last record it processed, which is why the same license is being used in the notification.
To fix this, you should move the gs.eventQueue() function inside the loop so that it triggers the event for each license that is about to expire, rather than just the last one.
var gr = new GlideRecord('alm_license');
var today = new GlideDateTime();
gr.addNotNullQuery('end_date');
gr.query();
var found = false;
while (gr.next()) {
var enddate = new GlideDateTime(gr.end_date);
var notifydate = new GlideDateTime(enddate);
notifydate.addDaysUTC(-10);
if (today.getNumericValue() >= notifydate.getNumericValue()) {
found = true;
var bt = gr.display_name;
gs.info("License " + gr.sys_id + " is about to expire.");
gs.eventQueue('license.expire', gr, enddate.toString(), bt.toString());
}
}
if (!found) {
gs.info('No licenses found expiring in 10 days.');
}
try this code and let me know if its working