
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2017 02:24 PM
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.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-26-2017 03:23 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 08:09 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 08:16 AM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-30-2017 08:39 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-15-2018 04:39 PM
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());