- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2022 11:25 PM
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');
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2022 01:13 AM
Hi
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.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Sagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-02-2022 01:13 AM
Hi
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.
If my answer helped you in any way, please then mark it as helpful.
Kind regards,
Sagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2022 10:57 PM
Cheers,
NB

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2022 12:05 PM
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');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-05-2022 06:33 PM
HI
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:
Select Parm1, because we are passing the email in Parm1 from eventQueue in Scheduled Jobs.
Please check
Shakeel Shaik 🙂