Add values to a custom field of type Set<User> shows "Cannot set value to custom field ..."
Hey,
I created a custom field of type User with mutli value and a user group defined as value-list.
I want to create a workflow to inherit that field to subtasks, so I copied and changed the standard workflow for inherit assignee. The workflow below throws an exception and shows "Cannot set value to custom field Architect".
var entities = require('@jetbrains/youtrack-scripting-api/entities');
exports.rule = entities.Issue.onChange({
title: 'Update architects for subtask when parent issue is reassigned',
guard: function(ctx) {
return ctx.issue.fields.Architect && ctx.issue.fields.Architect.isChanged;
},
action: function(ctx) {
var issue = ctx.issue;
var safeSetArchitect = function(subtask) {
if (subtask.project && subtask.isReported && !subtask.project.isArchived) {
if (subtask.project.key === issue.project.key || subtask.project.findFieldByName(ctx.Architect.name)) {
console.log('try to add architects to', subtask.id);
subtask.fields.Architect.clear();
issue.fields.Architect.forEach(function(v) {
subtask.fields.Architect.add(v);
});
}
}
};
issue.links['parent for'].forEach(safeSetArchitect);
},
requirements: {
Architect: {
type: entities.User.fieldType,
multi: true
},
Subtask: {
type: entities.IssueLinkPrototype,
name: 'Subtask',
outward: 'parent for',
inward: 'subtask of'
}
}
});
Maybe something obvious I'm doing wrong here.
Thanks for any help 👍
Please sign in to leave a comment.
Hello,
Please try locating the user using findByLogin() method (https://www.jetbrains.com/help/youtrack/standalone/v1-User.html#findByLogin) before setting the Architect field. So the process is as follows: take parent's architect, takes their login, find the user object using login, assign it to the child's architect field.
Also, please use console.log() to display what in fact is trying to be set as child's architect value.
Please let me know the results, I'm looking forward to your reply.
Thanks for the quick reply.
I added those lines:
What it tries to add looks like a normal user:
But still the same error :-(
Hello Christof,
Would you please make sure that the user that should be set as Assignee is added to the Assignee field values for each related project? The mentioned issue may occur when you are trying to Assign a user that does not exist in the Assignee list.
Hello Oleg,
I'm sure the assignee exists as a user on the project assignee list. Anything related to the usage of a Set<User> here?
Hello,
Please accept my apologies for the delayed response. Would you please try to set the required Assignee to the problematic issue to make sure that you have enough permissions for this? Also, would you please try to modify your code in the following manner and test it:
Please let us know your results.