My Scheduled Script Execution is failing to run and not showing in the Event Log

nborowiak
Tera Contributor

I have various Scheduled Scripts that are failing to Execute, even when I click the Execute Now button. We paid a vendor to come in and code this for us but I believe there may be a fault or issue in how they coded this. The encoded query is working as intended as I opened the table and applied the same filters that you see below and that provided a list of cases. However, this leads me to believe that the code itself is bad or not working as intended. This job is to run when the encoded query is satisfied > a notification email is then shot off because it's trigger is this event firing off. Please let me know where the code is wrong or incorrect.

var gr = new GlideRecord("sn_hr_core_case_operations");
gr.addEncodedQuery('active=true^hr_service=680a02079f1322003be01050a57fcf85^u_actual_return_dateISEMPTY^u_select_the_type_of_leave_you_would_like_to_request=Continuous');
gr.query();
while (gr.next()) {
    var dueDate = new GlideDate();
    dueDate.setValue(gr.u_approved_start_date);
    var today = new GlideDateTime();
    var diff = new GlideDuration();
    diff = GlideDate.subtract(today, dueDate).getRoundedDayPart();
    gs.info("Diff: " + diff + " " + gr.number);
    if (diff == '-172')
        gs.eventQueue('sn_hr_core.6month.prior.to.expectedstart', gr, 'LOA@email.com');
}
1 ACCEPTED SOLUTION

Sagar Agarwal
Mega Guru

Hi @nborowiak 

 

Can you check the "Run As" field for the scheduled Job? I am assuming the "Run as" field would have a contractor account and not that contractor account is inactivated/disabled you script stopped running.

Update the script to the System Administrator account or any other active admin user in the system.

find_real_file.png

 

 

If my answer helped you in any way, please then mark it as helpful.

Kind regards,

Sagar

View solution in original post

5 REPLIES 5

Sagar Agarwal
Mega Guru

Hi @nborowiak 

 

Can you check the "Run As" field for the scheduled Job? I am assuming the "Run as" field would have a contractor account and not that contractor account is inactivated/disabled you script stopped running.

Update the script to the System Administrator account or any other active admin user in the system.

find_real_file.png

 

 

If my answer helped you in any way, please then mark it as helpful.

Kind regards,

Sagar

@sagarAgarwal - Yup! This was what the issue was! I would think that an experienced vendor would know better to make a rookie mistake such as this! Much appreciated to all the others that commented as well!

 

Cheers,

NB

John Zhang1
Kilo Patron
Kilo Patron

Before you can check whether the notification is triggered, I added few steps (step 1 - step 2) to verify the returned values:  Can you run the following script and let me know each returned value (log.info) so I can tell you what is the septs?

var gr = new GlideRecord("sn_hr_core_case_operations");
gr.addEncodedQuery('active=true^hr_service=680a02079f1322003be01050a57fcf85^u_actual_return_dateISEMPTY^u_select_the_type_of_leave_you_would_like_to_request=Continuous');
gr.query();
while (gr.next()) {
var dueDate = new GlideDate();
gs.info("Check approved start date" + gr.u_approved_start_date); //step 1
dueDate.setValue(gr.u_approved_start_date);
var today = new GlideDateTime();
var diff = new GlideDuration();
diff = GlideDate.subtract(today, dueDate).getRoundedDayPart();
gs.info("Diff: " + diff + " " + gr.number);
gs.info("Check date diff value " + gr.number ); //step 2
if (diff == '-172'){
gs.info("Check wheter notification event is processed"); ////step 3
gs.eventQueue('sn_hr_core.6month.prior.to.expectedstart', gr, 'LOA@email.com');
}
}

 

 

Shakeel Shaik
Giga Sage
Giga Sage

HI @nborowiak 

 

Remove 

if (diff == '-172')
        gs.eventQueue('sn_hr_core.6month.prior.to.expectedstart', gr, 'LOA@email.com');

 

Add

 if (diff === -172)
gs.eventQueue('sn_hr_core.6month.prior.to.expectedstart', gr, 'LOA@email.com', '');

---------------------------------------------------------------------------------------------------------------------

In Notification:

find_real_file.png

 

Select Parm1, because we are passing the email in Parm1 from eventQueue in Scheduled Jobs.

 

Please check 

 

 

Thanks,
Shakeel Shaik 🙂