Condition for scheduled job

KristyS
Kilo Guru

I am new to scripting and need assistances with creating a conditional script for a scheduled job.

I need the job to execute based on the 1st day of the month, 2nd day of the month, every Friday, and last day of the month.

1 ACCEPTED SOLUTION

Hey Kristy,



That should be pretty doable as well.  



Try adding this script to the script block (remove the "gs.print" lines) of a daily run job and then doing whatever you need in the if condition.   It will only do what you need on 1st 2nd last and Fridays.



Run the below code as is in the background scripts to see the values printed out, since today is Friday you will see "hello" tomorrow you would not see "hello" since it is in the if block




var gdt2 = new GlideDateTime();


gdt2.setDayOfMonthLocalTime(31);




var gdt = new GlideDateTime();


var checkLast = new GlideDateTime();


checkLast = checkLast.setDayOfMonthLocalTime(31);


if(gdt.getDayOfWeekLocalTime() == 5 || gdt.getDayOfMonthLocalTime() == 1|| gdt.getDayOfMonthLocalTime()() == 2 || gdt2.getDayOfMonthLocalTime() == gdt.getDayOfMonth()){


  //run script here


  gs.print('hello');


}


gs.print(gdt.getDayOfWeekLocalTime());


gs.print(gdt.getDayOfMonthLocalTime());


gs.print(gdt2.getDayOfMonthLocalTime());





Hopefully that helps!



Best,


Andrew


View solution in original post

8 REPLIES 8

Hey Kristy,



Yes if that script does what you want it to, now in the if statement you just have to type "return 'true'" where you have the empty space since the condition is looking for a true or false evaluation.



However there is a different issue at hand as well if 'execute now' does not work.   Execute now will show you what happens when the condition evaluates to true so if execute now is not working, nothing will occur even if the condition does evaluate to true.



Make sure that your template is on the correct table, the template defines the record that will be created.



Best,


Andrew


Thank you Andrew!


If I remove the conditional script then the template creates a task from the Execute Now option.     I will continue to work with my script.


Andrew,


I had to return a result to equal true inside of a function then output the function. Here is a copy of my script to hopefully help someone in the future.





Best Regards,



Kristy Stevens


Neha Mishra
Giga Contributor

Thanks,this worked.

 

I would like to highlight one point here. If you are trying to get the weekof the day using the condition in Scoped application ,use getDayofWeekLocalTime instead of getDayofWeek.

var gdt = new GlideDateTime("2011-12-01 12:00:00");
gs.print(gdt.getDayOfWeekLocalTime());