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

Allen Andreas
Administrator
Administrator

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!

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"

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!

knopbrent
Tera Contributor

@Ankur Bawiskar 

Hi Ankur

If you dont mind, can you help me in fixing this issue ?

 

Thanks in advance