Scheduled job not working

SindhujaD
Tera Contributor

Hello,

I have got a requirement to trigger a notification if the Issue is due in 10 business days. I'm using the event to trigger and trying to call the event in scheduled job.

 

But the event is fired and my notification got triggered through background script, and the same script im implementing in my scheduled job but not working here, I have checked in event log , no event logs are there if im trying using the scheduled job. Much appreciated your help. Thank you!

9 REPLIES 9

Hi @SindhujaD ,

Use GlideDateTime instead of GlideDate. Also you can query by days before due date on filter and use that in your encoded query.

EhabPilloor_0-1749824576945.png

This is an example you can do on filter, run it and copy query from breadcrumb and use it in your encoded query.

 

Regards,

Ehab Pilloor

Hi Ehab,

I have modified my script with GlideDateTime , but still it is not working, and also we can't run a filter with this condition as we have to exclude saturdays and sundays.

Hello @SindhujaD , have you tried this ?

Hello @SindhujaD try this script and change field name as according

var today = new GlideDateTime();
today.setDisplayValue(today.getDate());

var issue = new GlideRecord('sn_grc_issue'); 
issue.addEncodedQuery("active=true^due_dateISNOTEMPTY"); 
issue.query(); 

while (issue.next()) {
    var dueDate = new GlideDateTime(issue.due_date);
    dueDate.setDisplayValue(dueDate.getDate());

    var tempDate = new GlideDateTime(today);
    var businessDays = 0;

    while (tempDate.compareTo(dueDate) <= 0) {
        var dayOfWeek = tempDate.getDayOfWeek(); // 1=Sun, 7=Sat

        if (dayOfWeek != 1 && dayOfWeek != 7) {
            businessDays++;
        }

        tempDate.addDaysLocalTime(1);
    }

    if (businessDays === 10) {
        gs.info('Due in exactly 10 business days: ' + issue.number);
        // gs.eventQueue("sn_grc.issues.due_in_10_business_days", issue, issue.assigned_to.email);
    }
}

danmjunqueira
Kilo Guru

Hello,

You’re on the right track using an event to trigger the notification, but the issue likely lies in how the scheduled job is set up or executed. Here are some points to help troubleshoot:


Check if the scheduled job is actually running

Verify the scheduled job has run by checking the sys_trigger table.

Add simple gs.info() logs in the script to confirm execution.

Ensure the GlideRecord query returns results


If your script depends on querying records (e.g., Issues due in 10 business days), confirm that the GlideRecord query is returning data in the scheduled job context.


Check user context of the scheduled job

Scheduled jobs typically run as the System user. If your script logic or event requires a specific user or role, make sure it's not blocked.

Use gs.eventQueue() correctly

Double-check that you're calling the event like this:

gs.eventQueue("your.event.name", gr, gr.sys_id, gr.number);

Test manually inside a background script

If the event works in background scripts but not in the scheduled job, compare them line by line and ensure the scheduled job includes all necessary setup (like querying and looping over records).


Enable debug logs for events

You can enable com.glide.sys.log_event property to true to see more detailed logs about event processing.