
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2022 10:43 AM
I have been asked to setup operational task. We are going to use Service Catalog to create requests with the task to do the work. I was going to use flow designer to order the items when they are needed. Daily ones are easy enough as well as weekly. However I have one that they want to fire on the last Tuesday of the month and one that needs to fire on the 1st weekday of the month. How would get these ones to fine?
Solved! Go to Solution.
- Labels:
-
flow designer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2022 02:32 AM
I would create a custom action that instead takes a date/time variable as input.
Then in the script use add days method, and evaluate if the new date is within the same month or not, that way you would know if it's the last thursday, or whatever day, in any given month or not.
This flow could run weekly.
Here's a how I'm thinking;
var inputDate = someDateToCheck;
var checkLastDayOfMonth = inputDate.addDays(7);
if (checkLastDayOfMonth.getMonth() > inputDate.getMonth() )
return true;
else
return false;
The second example when wanting to have the first weekday of the month, is a bit more complex. I can think of two different approaches.
Either you run it daily, and in the script evaluate if it is the first weekday of the month (can also be done with GlideDateTime functions), but it would also require you to evaluate and know if the job already has been run a particular month or not. I'm not sure if the second part is doable, I don't know if you can check this somehow.
The other option is to run the Flow monthly, on the first day of the month, and in a custom script evaluate if its a weekday or not. If it's a weekend, the action should return a number of hours the flow should wait (in an wait action) until continuing the trigger.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-03-2022 02:32 AM
I would create a custom action that instead takes a date/time variable as input.
Then in the script use add days method, and evaluate if the new date is within the same month or not, that way you would know if it's the last thursday, or whatever day, in any given month or not.
This flow could run weekly.
Here's a how I'm thinking;
var inputDate = someDateToCheck;
var checkLastDayOfMonth = inputDate.addDays(7);
if (checkLastDayOfMonth.getMonth() > inputDate.getMonth() )
return true;
else
return false;
The second example when wanting to have the first weekday of the month, is a bit more complex. I can think of two different approaches.
Either you run it daily, and in the script evaluate if it is the first weekday of the month (can also be done with GlideDateTime functions), but it would also require you to evaluate and know if the job already has been run a particular month or not. I'm not sure if the second part is doable, I don't know if you can check this somehow.
The other option is to run the Flow monthly, on the first day of the month, and in a custom script evaluate if its a weekday or not. If it's a weekend, the action should return a number of hours the flow should wait (in an wait action) until continuing the trigger.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-06-2022 04:22 PM
I tried running your script in background scripts. When I log checkLastDayOfMonth I get undefined. I set inputDate to todays date.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 12:39 PM
Oh, it was not by far a completed script, more an attempt to explain, in pseudo-code, how I would go about to find out if a given date is the last (monday/tuesday etc.) of a given month.
If you want something that works in scripts background, then this is more accurate.
var inputDate = new GlideDateTime('2022-09-28'); // try setting some different dates as needed to verify correct results
var compareDate = new GlideDateTime(testDate);
compareDate.addDaysUTC(7);
if (inputDate.getMonthUTC() < compareDate.getMonthUTC())
gs.info('month is different');
else
gs.info('month is same');
You still need to create a custom Flow action, that takes a Date as input, then add a script step, and in that script step, do this comparison, and return a true/false if it is time to continue processing the flow.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2022 12:43 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-09-2022 11:18 AM
Am I understanding this correctly. I run this weekly on the day I want. Then if the action returns true then Know it is the last day of that month?