Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Scheduled Data Collection Failing Conditional Script

jlaps
Kilo Sage

Good afternoon community,

I am configuring a scheduled data collection job in PA, to collect during the day results, and have the job running every 15 minutes to keep a particular dashboard up to date. I am trying to have this run only during business hours based on a schedule. The job runs fine if I uncheck the conditional box, so the job itself seems ok. The script itself however, I am guessing, must be failing. We are on Geneva, and it seems the script debugger is not active on this version, so I am looking for some help on where I am getting this incorrect. I am a js noob, so tweaking code I find and learning as I go.

function checkSchedule() {

var sched = new GlideSchedule('fdbab3b76fc91600220bbc775b3ee4e8','US/Eastern');

var schedTime = new GlideDateTime(); //get current dateTime in GMT

if (sched.isInSchedule(schedTime,'US/Eastern'))

                return yes;

      else

              return no;

}

According to the job log, this job runs but with ZERO edits. If I uncheck the conditional box, thus bypassing the script, it runs as expected. Where am I messing the script above up? FYI, this schedule is all day on weekdays, so it SHOULD be coming back as true, and running the script.

Thanks!

Jeff

1 ACCEPTED SOLUTION

Arnoud Kooi
ServiceNow Employee
ServiceNow Employee

You defined the function, you should call it by adding the line after the script:



checkSchedule();



If its not working you can test it by running it in a background script and print the result



find_real_file.png


View solution in original post

4 REPLIES 4

Arnoud Kooi
ServiceNow Employee
ServiceNow Employee

I have not tested but you should return true/false, not yes/no


And are you calling the function you are creating?



function checkSchedule() {


  var sched = new GlideSchedule('fdbab3b76fc91600220bbc775b3ee4e8','US/Eastern');


  var schedTime = new GlideDateTime(); //get current dateTime in GMT


  if (sched.isInSchedule(schedTime,'US/Eastern'))                  


      return true;        


  else                


      return false;


}


checkSchedule();


Arnoud,



Here is a screenshot of the scheduled job. I have the conditional box checked, which opens up the script area; I THINK I am calling it... also, I have it back to true/false here and it behaves the same way- as if false every time. Though again, the job runs but makes zero edits- this does seem weird, but perhaps it is just the way it is.


find_real_file.png



Job logs looks like this when it "fails"- when I uncheck the conditional box above, these jobs work (30 sec runs).


find_real_file.png



Thanks for the look Arnoud!


Jeff


Arnoud Kooi
ServiceNow Employee
ServiceNow Employee

You defined the function, you should call it by adding the line after the script:



checkSchedule();



If its not working you can test it by running it in a background script and print the result



find_real_file.png


Arnoud,



You cannot see it, but my head hung in shame for a moment when I saw this. You were correct, I had not called the function, and when I did, it worked as expected. Thank you Arnoud! I will report myself for public flogging .


Jeff