web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / AzureDevOps - Get & Up...
Power Automate
Unanswered

AzureDevOps - Get & Update all Related workitems

(0) ShareShare
ReportReport
Posted on by 36

In AzureDevOps - When the state of a specific workitem is changed , how do i - 

  • Get a list of all related workitems
  • Update the state of all the workitems 
Categories:
I have the same question (0)
  • Expiscornovus Profile Picture
    33,181 Most Valuable Professional on at
    Re: AzureDevOps - Get & Update all Related workitems

    Hi @Aiyoo_Da,

     

    Are the related items of the same work item type? If that is the case the updating of state is still manageable. Otherwise it is going to be a very challenging requirement. For example tasks have different state values compare to a user story work item 😁

     

    Below is an example of an approach. Which assumes the related work items are the same.

     

    Part 1 can be handled by a WIQL query. You can find the related work items by querying the System.LinkTypes.Related linktype:

    https://learn.microsoft.com/en-us/azure/devops/boards/queries/link-type-reference?view=azure-devops#work-link-types

     

    After that you can use a Filter Array and Select to retrieve the work item ids from that query.

     

    1. WIQL query in a Send an HTTP request to Azure DevOps action

     

    URI

    @{variables('ProjectName')}/_apis/wit/wiql?api-version=7.1-preview.2

     

    Body

    {
    "query": "SELECT [System.Id],[System.AssignedTo],[System.State],[System.Title],[System.Tags] 
    FROM workitemlinks 
    WHERE ([System.Links.LinkType] = 'System.LinkTypes.Related') AND ([Source].[System.Id] = '@{triggerOutputs()?['body/id']}')"
    }

     

    2. Filter Array action expressions

     

    From

    outputs('Send_an_HTTP_request_to_Azure_DevOps')?['body']['workItemRelations']

     

    Criteria (edit in advanced mode)

    @equals(item()['rel'], 'System.LinkTypes.Related')

     

    3. Select Action. From uses Body from Filter Array. Map is switch to Text mode and uses the expression below

    item()['target']['id']

     

     

    getrelatedworkitems.png

     

     

    Part 2 can be done via a Work Items update query. This is a PATCH request.

    Be aware, you might want to add an additional check to see if a work item has been updated by this flow.

     

    Otherwise you can get into a continues loop and retrigger the flow, because the flow is also updating the work item as well. You want to prevent that from happening 😄

     

    4. Apply to Each uses the Body of the Select

     

    5. A second Send an HTTP request to Azure DevOps action uses the below input for the PATCH request

     

    URI

    @{variables('ProjectName')}/_apis/wit/workitems/@{items('Apply_to_each')}?api-version=7.1-preview.2

     

    Headers

    {
     "Content-Type": "application/json-patch+json"
    }

     

    Body

    [
     {
     "op": "add",
     "path": "/fields/System.State",
     "value": "@{triggerOutputs()?['body/fields/System_State']}"
     }
    ]

     

    updatestate.png

  • Snulian Profile Picture
    2 on at
    Re: AzureDevOps - Get & Update all Related workitems

    Dear @Expiscornovus,

    I have found your solution, as I am currently in need of retrieving the related work items in order to update the work item afterwards.

    Your mentioned point about the flow getting stuck in a continues loop if no condition is added to check whether the work item has already been updated has occurred to me as well. I would like to know how you resolved it, as I currently have no reference point to determine how to address this.

     

    Thank you in advance for your time and assistance.

     

    Best regards,
    Snulian

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 462 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 456 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard