cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Update task due date to either following weekday or following friday

I'm working on a flow where a task depending on the bucket should either update the due date to the following weekday or the following friday. 

 

So far I have the conditions set up to sort the tasks when they're triggered, that part works, but I can't figure out the string for it to change the due date to either the next week day (not sat/sun), or the following friday. 

3 ACCEPTED SOLUTIONS

Accepted Solutions
efialttes
Super User
Super User

Hi!

I guess you will calculate first the new due date, then check if weekend right? if so, you can use dayOfWeek() WDL function to identify saturdays and sundays.

Let's assume you store the new due date in a variable called 'myCandidateDueDate'.

if dayOfWeek equals 0 (sunday) -> add 1 days

if dayOfWeek equals 6 (saturday) -> add 2 days

any other result -> already a working date

 

THis WDL expression can do the magic

if(equals(dayOfWeek(variables('myCandidateDueDate')),0),addDays(variables('myCandidateDueDate'),1),if(equals(dayOfWeek(variables('myCandidateDueDate')),6),addDays(variables('myCandidateDueDate'),2),variables('myCandidateDueDate')))

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

Anonymous
Not applicable

Hi @efialttes

I have now also tested if it worked if I switched out the oldStartDate with the completed date time. 

 

It gives me an output that looks like this: 

2020-06-03T11:03:09.4094494Z

 

I set up the new start date with the following expression. 

if(equals(dayOfWeek(variables('CompleteDate')),0),addDays(variables('CompleteDate'),1),if(equals(dayOfWeek(variables('CompleteDate')),2),addDays(variables('CompleteDate'),6),if(equals(dayOfWeek(variables('CompleteDate')),3),addDays(variables('CompleteDate'),5),if(equals(dayOfWeek(variables('CompleteDate')),4),addDays(variables('CompleteDate'),4),if(equals(dayOfWeek(variables('CompleteDate')),5),addDays(variables('CompleteDate'),3),if(equals(dayOfWeek(variables('CompleteDate')),6),addDays(variables('CompleteDate'),2),addDays(variables('CompleteDate'),7)))))))

 

Unfortunately, the flow still runs without any sign of stopping, and the task is never reactivated.

 

I'm completely out of ideas now on how to make this flow run as described 😞

View solution in original post

Anonymous
Not applicable

Okay, so I fixed it, wrote the whole set up down, and when I tried to post it, the page went to authentication mail. 

 

So here's the short description of the answer. 

 

Taking root from your idea, I changed it a bit, due to lack of access or uneccesary actions. 

 

The flow is now as follows, when a task i completed, a variable is made with the time of completion. 

 

A condition then checks if the bucket ID is similar to the first condition. 

If true, it composes an object that sets the a date to the next start date compared to when the task is completed.  (daily tasks are set to the next mon-fri, and weekly is setting the next start date to the following monday. 

The Due date is set to take the composed date and add the number of days there is to complete the task. 

View solution in original post

11 REPLIES 11
efialttes
Super User
Super User

Hi!

I guess you will calculate first the new due date, then check if weekend right? if so, you can use dayOfWeek() WDL function to identify saturdays and sundays.

Let's assume you store the new due date in a variable called 'myCandidateDueDate'.

if dayOfWeek equals 0 (sunday) -> add 1 days

if dayOfWeek equals 6 (saturday) -> add 2 days

any other result -> already a working date

 

THis WDL expression can do the magic

if(equals(dayOfWeek(variables('myCandidateDueDate')),0),addDays(variables('myCandidateDueDate'),1),if(equals(dayOfWeek(variables('myCandidateDueDate')),6),addDays(variables('myCandidateDueDate'),2),variables('myCandidateDueDate')))

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Anonymous
Not applicable

Hi @efialttes 

 

Flow won't allow me to initialize a variable after I have created the new due date as I'm creating it within an apply to each and a condition. Overview of flowOverview of flow

 

And I changed my plan a bit. My new plan is that when a task is completed, it will check the bucket name and sort accordingly. So:

  • If the bucket name is Daily, it will have no start date, but have the due date set to the following day, unless it's a sat or sunday. 
  • If the bucket name is Weekly, it will set the start date to the following Monday and have the due date to be the following Friday. 
  • If the bucket name is 14th day, the start date will add 14 days to the current start date, and the due date will be 5 days after the start date. 
  • If the bucket name is Monthly, the start date should go to a specific day of the next month, e.g. the 14th, and have due date set to 5 days later. 

I'm guessing I will still have to create a string, with the current start date of the finished task. 

 

But I'm not sure how I set it up so I the new startdate updates accordingly to the wishes above. 

 

I assume that the due date would be the startdate plus 5 days 🙂 

 

Hi!

"Flow won't allow me to initialize a variable after I have created the new due date as I'm creating it within an apply to each and a condition. "

If you are using an 'Apply to each' you can initialize the variable before the 'Apply to each' by means of 'Initialize variable', now you probably need to reset it in each iteration by means of a 'Set variable' inside your 'Apply to each', either at the beginning or at the end of it

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Anonymous
Not applicable

Hi @efialttes 

 

I'm still trying to figure out the right actions and string. 

 

As I mentioned in my last comment, I changed my flow structure a bit, so now it's as follows:

  • If the bucket name is Daily, it will have no start date, but have the due date set to the following day, unless it's a sat or sunday. 
  • If the bucket name is Weekly, it will set the start date to the following Monday and have the due date to be the following Friday. 
  • If the bucket name is 14th day, the start date will add 14 days to the current start date, and the due date will be 5 days after the start date. 
  • If the bucket name is Monthly, the start date should go to a specific day of the next month, e.g. the 14th, and have due date set to 5 days later. 

I have created a string named 'oldStartDate' that references the start date of the finished task. 

 

I set the new due date times to 'oldStartDate' plus 5 days.

I tried to create the new start date with the expression you wrote with it based on the old start date like this: 

if(equals(dayOfWeek(variables('oldStartDate')),5),addDays(variables('oldStartDate'),3),if(equals(dayOfWeek(variables('oldStartDate')),6),addDays(variables('oldStartDate'),2),addDays(variables('oldStartDate'),1)))

 

But it has now run for about 15 minutes and hasn't executed it yet, so obviously I did something wrong, and I'm hoping you can help me write the correct expression.

 

Thank you in advance 🙂

Hi!

Can you share a screenshot from current oldStartDate value? You can get it by inspecting flow execution

Thanx!



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Anonymous
Not applicable

2020-06-02_15-39-33.png

 

The problem is definitely somewhere in the Apply to each action, but as it wont give up on running, I have to cancel it, and then it wont show me the process  😕

Anonymous
Not applicable

Hi @efialttes

I have now also tested if it worked if I switched out the oldStartDate with the completed date time. 

 

It gives me an output that looks like this: 

2020-06-03T11:03:09.4094494Z

 

I set up the new start date with the following expression. 

if(equals(dayOfWeek(variables('CompleteDate')),0),addDays(variables('CompleteDate'),1),if(equals(dayOfWeek(variables('CompleteDate')),2),addDays(variables('CompleteDate'),6),if(equals(dayOfWeek(variables('CompleteDate')),3),addDays(variables('CompleteDate'),5),if(equals(dayOfWeek(variables('CompleteDate')),4),addDays(variables('CompleteDate'),4),if(equals(dayOfWeek(variables('CompleteDate')),5),addDays(variables('CompleteDate'),3),if(equals(dayOfWeek(variables('CompleteDate')),6),addDays(variables('CompleteDate'),2),addDays(variables('CompleteDate'),7)))))))

 

Unfortunately, the flow still runs without any sign of stopping, and the task is never reactivated.

 

I'm completely out of ideas now on how to make this flow run as described 😞

Hi again!

 

In your current flow design you are assigning 'List buckets' output to your 'Apply to each' input, right?

If so, it seems the intention behind your Condition is to verify if the completed task belongs to 'Daily' bucket, if so you update it, if not you just terminate flow execution, right?

 

Are my assumptions correct?

Then the problem is, as far as I remember output from trigger 'When a task is completed' provides tons of details related to the task, also the Bucket Id but not the Bucket Name.And in your condition it seems you are verifying if current iteration bucket has the target bucket name. But you are not verifying if your trigger's output bucket id is your target one.

 

I would adda 'Initialize' action block just before your 'apply to each', let's call it 'DailyBucketId', type string, value empty.

 

Now, on your condition true branch I would add a 'Set variable' action block, name 'DailyBucketId', assign as its value the 'List buckets' 'Bucket id' - you can select it from the Dynamic content menu.

 

Then I would add another condition after, out of the 'Apply to each'. THis condition shall compare 'Bucket id' from trigger output, and 'DailyBucketID'. Now on its true branch I would add the 'Delay' and 'Update task' action blocks

 

Hope this makes sense



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Anonymous
Not applicable

Okay, so I fixed it, wrote the whole set up down, and when I tried to post it, the page went to authentication mail. 

 

So here's the short description of the answer. 

 

Taking root from your idea, I changed it a bit, due to lack of access or uneccesary actions. 

 

The flow is now as follows, when a task i completed, a variable is made with the time of completion. 

 

A condition then checks if the bucket ID is similar to the first condition. 

If true, it composes an object that sets the a date to the next start date compared to when the task is completed.  (daily tasks are set to the next mon-fri, and weekly is setting the next start date to the following monday. 

The Due date is set to take the composed date and add the number of days there is to complete the task. 

@Anonymous 

I saw you marked this topic as "Solved" by clicking "Accept as a solution" in your last post. Thanx for taking the time to describe the final solution implemented, this way others with a similar problem can find a solution faster. Please also note you can even select several responses as solution, even from different community members!

 

Flow_AcceptSolution.png

 

 

Thanx for your help making this community great!

 



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



takolota
Super User
Super User

How to get the date of the next upcoming day of the week.
Choose a day of the week, ex: 5 for Friday, and get the date of the next Friday starting from utcnow().

 

https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/Date-of-Next-Chosen-Day-of-Week/td-p/146...

 

I often see requests for timing things a certain time on a certain day of the week and people respond with an expression formula for that person’s requested day of the week and only their requested day of the week. With this, we shouldn’t need to find a different formula for each day.

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Users online (4,858)