Rewriting old workflow rules with conditional transitions in the statemachine

Answered

Hello 

I'm wondering how can I rewrite a following part of my statemachine rule to the new workflow syntax, so the behaviour is preserved (specifically: choose a different target Status value based on a condition):

Thank you in advance!

0
1 comment
Official comment

Hello,

I am afraid, the current version of workflow does not support this scenario out of the box. As a workaround, I suggest you create a separate field value, for example:

    Testing: {
transitions: {
finish: {
targetState: 'TemporaryState'
}
}
}

Then, you can extend this logic and select the required value after setting TemporaryState. For this, use the onChange rule. For example:

var entities = require('@jetbrains/youtrack-scripting-api/entities');
exports.rule = entities.Issue.onChange({
title: 'Automatically-change-temporary-state',
guard: function(ctx) {
return ctx.issue.fields.becomes(ctx.Status, ctx.Status.TemporaryState);
},
action: function(ctx) {
var issue = ctx.issue;
var fs = issue.fields;
if (fs.MergedToDevelop === null)
fs.Status = ctx.Status.Finishing;
else
fs.Status = ctx.Status.Merging;
},
requirements: {
MergedToDevelop: {
type: entities.Field.stringType,
name: 'Merged to develop'
},
Status: {
type: entities.EnumField.fieldType,
name: 'Status',
TemporaryState: {
name: 'TemporaryState'
},
Finishing: {
name: 'Finishing'
},
Merging: {
name: 'Merging'
}
}
}
});

I hope it will be helpful. Should you have any further questions, feel free to contact us.

Please sign in to leave a comment.