1

Context

I want to create a Power-Automate flow that automatically creates a sub-task in Azure DevOps when the Effort of a PBI is set.

When the Effort field goes from blank to a positive value, the task should be added (using the newly set Effort value as the task's Original Estimate and Remaining Work).

I managed to create a flow that does that using When a work item is update trigger.

Problem

The flow runs too often (whenever the work item changes, as long as the Effort is > 0).

Question

What would be the best way to ensure this flow runs only once per PBI?

Thoughts

  • Perhaps check for the presence of child tasks?
  • Perhaps set a hidden property when adding the task the first time and check that property afterwards?
Batesias
  • 1,914
  • 1
  • 12
  • 22
  • You could also check which values have changed via the Updates method of the DevOps REST API, https://learn.microsoft.com/en-us/rest/api/azure/devops/wit/updates/list?view=azure-devops-rest-6.0&tabs=HTTP I will add that part to my answer. – Expiscornovus Oct 07 '22 at 21:48

1 Answers1

3

You could add a trigger condition to the settings of your trigger action. Use the following expression:

@greater(triggerOutputs()?['body/fields/Microsoft_VSTS_Scheduling_Effort'], 0)

enter image description here

  1. Add a Send an HTTP request action directly after the trigger. Use the following URI:

    YourProjectName/_apis/wit/workItems/@{triggerOutputs()?['body/id']}/updates?api-version=6.0

  2. Add a Filter Array. Use this expression for the From

    body('Send_an_HTTP_request_to_Azure_DevOps')['value']

  3. In the where of the Filter Array use the following expression which you add via the advanced mode:

    @greater(length(string(item()?['fields']?['Microsoft.VSTS.Scheduling.Effort']?['newValue'])), 0)

  4. In a condition check if the Filter Array returns no results. If it does, the value of Effort has not been changed in the past and you can safely create your new task

    length(body('Filter_array'))

is equal to 1

enter image description here

Expiscornovus
  • 1,222
  • 1
  • 3
  • 7
  • Works like a charm! The only mistake is that the last condition needs to be `is equal to` **1** instead of **0** because of the first edit. You should probably edit your answer ;) Thanks! – Batesias Oct 09 '22 at 18:51
  • Thanks for letting me know about that mistake in my condition :) – Expiscornovus Oct 10 '22 at 07:40
  • @Expiscornovus what would be the trigger condition to check only if Titile(string) is updated? like: @greater(triggerOutputs()?['body/fields/System_Title'], 0) – Kurkula Oct 24 '22 at 19:24
  • That expression is referencing the Send an HTTP request to Azure DevOps actions within the Filter Array. So for the Title field it would be: `@greater(length(string(item()?['fields']?['System.Title']?['newValue'])), 0)` – Expiscornovus Oct 25 '22 at 10:20