Operational Tasks - Via Service Catalog

Brian Lancaster
Tera Sage

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?

1 ACCEPTED SOLUTION

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.

View solution in original post

13 REPLIES 13

I used the second option for the first first weekday of the month. I check what the first day of the month is and then I go in and wait 24 to 48 hours before creating the request if the day of the week is Sat or Sunday.

Parth10243
Tera Contributor

I think this solution would not work. This is because as per the script we are doing

var checkLastDayOfMonth = inputDate.addDays(7);

 

However, addDays function doesn't return anything. So this would be incorrect. Plus the other bug is when we run the script in December (12), the next month January(1), would actually be smaller number. This would cause the flow to never trigger in the month of December.

This could be a solution. IF we trigger it on every monday. 

var gd = new GlideDateTime();
var gdt = new GlideDateTime();
gdt.addDays(7);

if (gd.getMonth() != gdt.getMonth()){
  return true;
}else{
  return false;
}

Thank you for your input, but as I stated earlier that section is not to be treated as actual code. It was more of a pseudo code attempt, to show my thinking in a quick way.

I did provide a more accurate code example later in the thread.