Scheduled job not triggering the Event

knopbrent
Tera Contributor

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 modelPhase CloudCloud Review PurposeSLO (# of days since Submitted)
SaaSTrial 35
SaaSPilot OR Prod 140
I/PaaS Cloud account35
I/PaaSDev OR Test 35
I/PaaSPilot OR Prod 60

 

  1. Depending on the service model and phase, set the SLO value.
  2. Check if today()-Submitted date=(SLO-5), send first email
  3. 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, "", "");
            }
        }
    }
}

 

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@knopbrent 

can you share debugging have you done so far by adding logs etc?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

 

HI Ankur

I am about to resolve the issue, but I am not able to calculate the duration between 2 date/time fields. I want to get the difference in "Number of Days". I am trying this in scoped app ut I was not able to achieve it. Do you have any idea ?

 

Thanks in advance