Reputation: 326
I want to create rule like: When custom field value is set to X then change state od Task to New. Can it be done?
It's hard to belive this isn't possible but I can't find a way to do it.
Upvotes: 0
Views: 2664
Reputation: 5012
Default custom rule does not support changing state. There are two workarounds you can refer to.
Workaround1:
You can customize a field to decide whether to change the state, trigger a webhook when the field changes, and then trigger a pipeline through this webhook. In the pipeline, the state of the current work item is changed by running the REST API Work Items – Update.
There are the detailed steps.
Set Trigger on this type of event to Work item updated, set Field to the customed field created at the first step.
Set the webhook created at the second step as the pipeline resource and run the REST API Work Items – Updateto update the state of the work item. There is the YAML for your reference:
resources:
webhooks:
- webhook: ChangeWIState ### Webhook alias
connection: ChangeNameSC ### Incoming webhook service connection
pool:
vmImage: ubuntu-latest
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
script: |
Write-Host ${{ parameters.ChangeWIState.resource.workItemId}}
$token = "<your PAT>"
$token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($token)"))
$url="https://dev.azure.com/<org name>/_apis/wit/workitems/${{ parameters.ChangeWIState.resource.workItemId}}?api-version=7.0"
$body = @'
[
{
"op": "add",
"path": "/fields/System.State",
"value": "New"
}
]
'@
$head = @{ Authorization =" Basic $token" }
$response = Invoke-RestMethod -Uri $url -Method PATCH -Headers $head -Body $body -ContentType application/json-patch+json
"ChangeWIState" is the name of my webhook and "ChangeNameSC" is the name of my servie connection.
Every time the field "ChangeState" changes, the pipeline will be triggered to run the REST API to change the state to new.
Workaround2:
You can use this extension "Work item form one click actions.
When the value of the field "Test" changes to "X", the state will change to "New".
Upvotes: 1