Scheduled job not triggering the Event
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 01:40 PM
Hi Community
I wrote a scheduled script to trigger a couple of events. 1st event will trigger 5 days before the SLO breach and the 2nd event will trigger on the breach day. Though I have the test data ready, I have tried many ways, but the events are not triggering and none of the notifications are sent out.
The SLO's are defined below
Service model | Phase Cloud | Cloud Review Purpose | SLO (# of days since Submitted) |
SaaS | Trial | 35 | |
SaaS | Pilot OR Prod | 140 | |
I/PaaS | Cloud account | 35 | |
I/PaaS | Dev OR Test | 35 | |
I/PaaS | Pilot OR Prod | 60 |
- Depending on the service model and phase, set the SLO value.
- Check if today()-Submitted date=(SLO-5), send first email
- Check if today()-Submitted date=SLO, send second email
Please review the code mentioned below and let me know where am I going wrong. Is there any API that doesnot support for the Scoped APPS ?
Thanks in advance
checkCloudReqslo();
function checkCloudReqslo() {
var SaaSTrialSlo = new GlideDateTime(gs.daysAgo(35));
var SaasPilotProdSlo = new GlideDateTime(gs.daysAgo(140));
var IPaasCloudaccountSlo = new GlideDateTime(gs.daysAgo(35));
var IPaasDevTestSlo = new GlideDateTime(gs.daysAgo(35));
var IPaasPilotProdSlo = new GlideDateTime(gs.daysAgo(60));
var slo_30 = new GlideDateTime(gs.daysAgo(30));
var gr = new GlideRecord("x_ibm_task_review");
gr.addQuery('state','=','4');
gr.query();
while (gr.next()) {
var submittedDate = new GlideDateTime(gr.u_submitted_date);
var submittedDate2 = submittedDate.getLocalDate();
var slo_30 = new GlideDateTime(gs.daysAgo(30));
var slo_135 = new GlideDateTime(gs.daysAgo(135));
var slo_55 = new GlideDateTime(gs.daysAgo(55));
if (gr.u_technology_type == 3) {
if ((gr.u_phase == 1) && (submittedDate2.getDate() == slo_30.getDate())) {
gs.eventQueue("x_usaa3_cloud_gove.notice_slo_breach5day", gr, "", "");
}
if ((gr.u_phase == 1) && (submittedDate2.getDate() == SaaSTrialSlo.getDate())) {
gs.eventQueue("x_usaa3_cloud_gove.notice_slo_breach", gr, "", "");
}
if ((gr.u_phase == 2 || gr.u_phase == 3) && (submittedDate2.getDate() == slo_135.getDate())) {
gs.eventQueue("x_usaa3_cloud_gove.notice_slo_breach5day", gr, "", "");
}
if ((gr.u_phase == 2 || gr.u_phase == 3) && (submittedDate2.getDate() == SaasPilotProdSlo.getDate())) {
gs.eventQueue("x_usaa3_cloud_gove.notice_slo_breach", gr, "", "");
}
} else if (gr.u_technology_type == 2 || gr.u_technology_type == 3) {
if ((gr.type_of_service == 12) && (submittedDate2.getDate() == slo_30.getDate())) {
gs.eventQueue("x_usaa3_cloud_gove.notice_slo_breach5day", gr, "", "");
}
if ((gr.type_of_service == 12) && (submittedDate2.getDate() == IPaasCloudaccountSlo.getDate())) {
gs.eventQueue("x_usaa3_cloud_gove.notice_slo_breach", gr, "", "");
}
if ((gr.u_phase == 8 || gr.u_phase == 9) && (submittedDate2.getDate() == slo_30.getDate())) {
gs.eventQueue("x_usaa3_cloud_gove.notice_slo_breach5day", gr, "", "");
}
if ((gr.u_phase == 8 || gr.u_phase == 9) && (submittedDate2.getDate() == IPaasDevTestSlo.getDate())) {
gs.eventQueue("x_usaa3_cloud_gove.notice_slo_breach", gr, "", "");
}
if ((gr.u_phase == 2 || gr.u_phase == 3) && (submittedDate2.getDate() == slo_55.getDate())) {
gs.eventQueue("x_usaa3_cloud_gove.notice_slo_breach5day", gr, "", "");
}
if ((gr.u_phase == 2 || gr.u_phase == 3) && (submittedDate2.getDate() == IPaasPilotProdSlo.getDate())) {
gs.eventQueue("x_usaa3_cloud_gove.notice_slo_breach", gr, "", "");
}
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2023 03:19 PM - edited 02-24-2023 03:22 PM
Hello,
I would recommend using appropriate logging to see what you are getting for your values...otherwise, you're just coding in the dark. Are your GlideDateTime objects actually being set correctly? Have you ensured that the conditions have even been met for this scheduled job to trigger? Are the events spelled correctly, etc.? Has your GlideRecord call actually found any records?
Please try looking into all those first.
From what I'm seeing, it looks correct, but obviously we don't know the other field names you're attempting to leverage as u_phase, etc. is custom, including the table and all that. Is this scheduled job in the right scope to see those records? Have you tried to test this in a background script with similar scope, does that work?
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 09:08 AM
HI Allen
I dont see any issues GlideDateTime objects, and also conditions are met for the scheduled job to trigger. Everything looks as expected.
I am getting the error mentioned below wen I have executed the script in the background.
"function getdate is not allowed in scope"

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 09:56 AM - edited 02-27-2023 09:57 AM
Hello,
I hope my initial reply was Helpful with what I asked as this helped us move to the next step of troubleshooting. It appears that it's stemming from you using getDate with the submittedDate2 variable, which is you getting a local date from the GlideDateTime object, but you then trying to use getDate off of that, is where I see the error popping up from. I'd recommend getting the date from a GlideDateTime object same as you did for everything else in your script and see if that works for you.
As getDate is allowed in scoped apps, but the way you're using it for that particular variable, may be causing an unintentional issue. All the other "getDate" methods resolve correctly in my testing.
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-27-2023 09:10 AM