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']

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']}"
}
]
