Workflow - populate field value from one to another

Hello,

I'm trying to set a workflow on change rule that will populate field value based on other field value.

Basically to take the value from one field to another.

Both fields are the same data type (state).

When I try to do that I get the following error:

Cannot set value to custom field "original-deliver-it"

What is wrong???

 

/**
* validate deliver id when status is not pending
*/

var entities = require('@jetbrains/youtrack-scripting-api/entities');
var workflow = require('@jetbrains/youtrack-scripting-api/workflow');

exports.rule = entities.Issue.onChange({
title: 'Validate-deliver-it-on-status-change',
guard: function(ctx) {
console.log(ctx.issue.fields.State.name);
return ctx.issue.fields.State.name !== "Pending";
},
action: function(ctx) {
var issue = ctx.issue;

workflow.check(!(issue.isChanged('State') && !issue.fields['Deliver-It'] && (issue.fields['Type'].name === 'Feature' || issue.fields['Type'].name === 'Epic')), 'You must set the Deliver-it and Target Version when issue is planned!');

//else -set value
console.log('else', issue.fields['original-deliver-it']);
issue.fields['original-deliver-it'] = issue.fields.['deliver-it'];
},
requirements: {
state: {
type: entities.State.fieldType
},
},
});

1 comment
Comment actions Permalink
Official comment

Hello,

This issue occurs because you are using a different set of values in these fields. To resolve it, you can use one of these ways:

1. If values are the same, you can merge these two fields to avoid the error. Please refer to the Merge Values with Another Set article for more information.

2. Alternatively, modify your rule in the following manner:

//issue.fields['original-deliver-it'] = issue.fields.['deliver-it'];

var value = ctx.DeliverIt.findValueByName(issue.fields['original-deliver-it'].name);
if (value)
issue.fields['deliver-it'] = value;
...
requirements: { DeliverIt: { type: entities.State.fieldType, name: 'deliver-it', }
}

I hope this helps. Should you have any further questions, feel free to contact us.

Please sign in to leave a comment.