Rest api - cannot change value through rest api with running State machine
I am not able to change value through rest api with running state machine. It works without state machine.
(From "In progress")
Rest api: /api/issues/DEMPClone-1
body:
{
"customFields":[
{
"name":"State",
"$type":"StateMachineIssueCustomField",
"value":{
"name":"Fixed"
}
}
]
}
State machine
var entities = require('@jetbrains/youtrack-scripting-api/entities'); exports.rule = entities.Issue.stateMachine({ title: 'Simple State Machine Usable in Non-Product Projects like Tooling-*.', stateFieldName: 'State', typeFieldName: 'Type', defaultMachine: { New: { initial: true, transitions: { start: { targetState: 'In Progress' }, reject: { targetState: 'Rejected' } } }, 'In Progress': { transitions: { fix: { targetState: 'Fixed' }, reject: { targetState: 'Rejected' } } }, Rejected: { transitions: { reopen: { targetState: 'Reopened' } } }, Fixed: { transitions: { reopen: { targetState: 'Reopened' } } }, Reopened: { transitions: { start: { targetState: 'In Progress' }, reject: { targetState: 'Rejected' } } } }, alternativeMachines: { Bug: { New: { initial: true, transitions: { start: { targetState: 'In Progress' }, 'mark as invalid': { targetState: 'Invalid' }, 'mark as duplicate': { targetState: 'Duplicate' }, 'won\'t fix': { targetState: "Won't Fix" } } }, 'In Progress': { transitions: { fix: { targetState: 'Fixed' }, 'mark as invalid': { targetState: 'Invalid' }, 'mark as duplicate': { targetState: 'Duplicate' }, 'won\'t fix': { targetState: "Won't Fix" } } }, Fixed: { transitions: { reopen: { targetState: 'Reopened' } } }, Invalid: { transitions: { reopen: { targetState: 'Reopened' } } }, Duplicate: { transitions: { reopen: { targetState: 'Reopened' } } }, "Won't fix": { transitions: { reopen: { targetState: 'Reopened' } } }, Reopened: { transitions: { start: { targetState: 'In Progress' }, 'mark as invalid': { targetState: 'Invalid' }, 'mark as duplicate': { targetState: 'Duplicate' }, 'won\'t fix': { targetState: "Won't Fix" } } } } }, requirements: { } });
Please sign in to leave a comment.
Hello M Sic, thank you for your question.
Ayagudza, thank you very much for your help. The method that you've suggested is indeed a valid method to update state machine custom fields. I've created an issue in our tracker so that we document this method and include it in our public documentation portal. Here it is: https://youtrack.jetbrains.com/issue/RDOC-1795 Please feel free to subscribe, comment or add any further details that you consider important there.
I had the same problem.
The browser devtool helped me.
Try this:
REST API: /api/issues/{id issue}/fields/{id field}
This works too:
Yes, that's true, thanks for mentioning it! As a matter of fact, it's often easier to update issues using commands via REST API than to update issue fields directly.