ownedField unable to get data

Hello,
I am trying to make a workflow that will output owner and description of multiple choice ownedField as a message whenever user chooses a Subsystem. Current messages I get only say "undefined". I want to display Owner and Description of a chosen Subsystem value (screenshot below).
Any help would be appreciated.

 

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

exports.rule = entities.Issue.onChange({
title: 'Message',
guard: function(ctx) {
var fs = ctx.issue.fields;
return fs.isChanged(ctx.Subsystem);
},
action: function(ctx) {
var issue = ctx.issue;
workflow.message(issue.fields.Subsystem.owner);
workflow.message(issue.fields.Subsystem.description);

},
requirements: {
Subsystem: {
type: entities.OwnedField.fieldType,
multi: true

}
}
});
3 comments
Comment actions Permalink
Official comment

Hi!

I'm Sergey from the Youtrack team.

In your case, you have a multi-value field, so the values are stores as a set. You should iterate through the set to get these values. For example, this action will work: 

action: function(ctx) {
var issue = ctx.issue;
issue.fields.Subsystem.forEach(function(sub) {
workflow.message(sub.owner.login);
workflow.message(sub.description);
});
},

P.S. if you'd like to get in touch with our support team directly for a quick answer to your question, please fill in a direct request at https://youtrack-support.jetbrains.com/hc/en-us/requests/ We'll be happy to help.

Comment actions Permalink

Thank you for your response,
The code works well when selecting 1-3 subsystems, but would it be possible to only display the message about the last selected Subsystem. Right now whenever a new subsystem is added the message is sent for each entry, which when choosing 4-5 subsystems fills up the whole screen. Basically I want to display only the last entry which forEach function would display

0
Comment actions Permalink

In my initial reply, I linked a doc where there's a description of the set as well as a bunch of set's methods. One of the methods is last() that should help you: https://www.jetbrains.com/help/youtrack/standalone/v1-Set.html#last Please check the link.

0

Please sign in to leave a comment.