
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
on 08-24-2021 02:39 AM
Hi there,
Sometimes you just need to get your hands on how many occurrences of this weekday it is in the month. For example when creating a scheduled job, which you should only run on the 3rd Monday of every month. This is also a pretty popular Community question. Loads of possibilities to achieve such, I'll be sharing one with using a Flow Designer Action.
Script
We would need to apply scripting, to find out the occurrence of a certain weekday in the current month. There's no API available for this. After some brainstorming, I came up with:
var input_value = 3;
var day = new GlideDate().getDayOfMonth();
var occurrence = Math.ceil(day / 7);
var answer = false;
if(occurrence == input_value) {
answer = true;
}
Basically, this would check for the 3rd (input_value = 3) occurrence of the current weekday in the current month. The output is a boolean value, either true or false.
Action
Let's transform this into a Flow Designer Action. An Action which we could use in a Scheduled Flow for example (instead of old school Scheduled Job). To make the script more dynamic, we need to change the "input_value", this should become the input of our Action.
Inputs could be:
Outputs pretty straightforward:
Having the Inputs and Outputs in place, we would only need to apply the script mentioned before. With slight adjustments, though not that tough to set up. The Script step could be something like:
Now simply save and publish the Action!
Scheduled Flow
A popular question on the Community is how to run a scheduled job, which should only run on a certain occurrence of a weekday in the month. While you can select as trigger "Weekly", there's no option to add an additional condition. So let's use our created Action for this!
And that's it. A Scheduled Flow which runs every Thursday at 03:01, which is just defined within the Trigger options. The Flow itself starts with our created Action, to check if the current weekday, is the third occurrence of a Thursday in the current month. If that's not the case, the Flow ends.
Share
An Update Set with this Flow Designer Action can be downloaded from Share:
- Flow Designer Action "Check day occurrence in a month"
---
If any questions or remarks, let me know!
If this post helped you in any way, I would appreciate it if you hit bookmark or mark it as helpful. Interested in more articles, blogs, videos, and Share projects on Flow Designer I published? - Flow Designer |
Kind regards,
Mark
2020-2021 ServiceNow Community MVP
2020-2021 ServiceNow Developer MVP
---
- 5,301 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hello Mark,
How could I modify this work looks for the last occurrence of a specific day in a month? Meaning I have to run a schedule that will fire on the last Tuesday of the month.
Edit: I have a question that someone pointed me to this article.
https://community.servicenow.com/community?id=community_question&sys_id=a0480257db2599d4bb4a474d1396...
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi Brian,
This could be a way to execute the flow on last weekday (for example monday) of a month
var gd = new GlideDateTime();
var gdt = new GlideDateTime();
gdt.addDays(7);
if (gd.getMonth() != gdt.getMonth()){
return true;
}else{
return false;
}