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 👍

5 comments
Comment actions Permalink

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. 

0
Comment actions Permalink

Thanks for the quick reply.

I added those lines:

issue.fields.Architect.forEach(function(v) {
var user = entities.User.findByLogin(v.login);
console.log('add user to architects', user);
subtask.fields.Architect.add(user);
});

What it tries to add looks like a normal user:

add user to architects,{"becomesRemoved": "false",
"isNew": "false",
"$$type": "User",
"toString": function() {},
"toShortString": function() {},
"required": function() {},
"becomes": function() {},
"isChanged": function() {},
"oldValue": function() {},
"canBeReadBy": function() {},
"canBeWrittenBy": function() {},
"canUnvoteIssue": function() {},
"canVoteIssue": function() {},
"email": "xxxxx",
"firstDayOfWeeks": "0",
"fullName": "xxxx",
"login": "ca",
"getSharedTag": function() {},
"getTag": function() {},
"timeZoneId": "xxxxx",
"visibleName": "xxxxx",
"hasRole": function() {},
"isBanned": "false",
"isInGroup": function() {},
"notify": function() {},
"sendJabber": function() {},
"sendMail": function() {},
"unvoteIssue": function() {},
"unwatchIssue": function() {},
"voteIssue": function() {},
"watchIssue": function() {}}

But still the same error :-( 

0
Comment actions Permalink

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. 

0
Comment actions Permalink

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?

0
Comment actions Permalink

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:

if (subtask.project.key === issue.project.key || subtask.project.findFieldByName(ctx.Architect.name)) {
var field = subtask.project.findFieldByName(ctx.Architect.name);
subtask.fields.Architect.clear();
issue.fields.Architect.forEach(function(v) {
if (field.values.has(v))
subtask.fields.Architect.add(v);
});
}

Please let us know your results.

 
0

Please sign in to leave a comment.