How can I set custom issue field which is based on 'Fixed in Build' field? Follow
I have custom field i.e. Affected Builds (type Build, Set of values - Fixed in Build).
I have external crash reporter which sends build number and I want to add this value to Affected Builds of the issue, but I don't know how can I fetch all builds to find value by name or id to add it to Affected Builds.
JS Workflow.
Please sign in to leave a comment.
The most simple way to get a value from its name is to use findValueByName method of BundleProjectCustomField (see https://www.jetbrains.com/help/youtrack/standalone/2017.3/v1-BundleProjectCustomField.html#findValueByName). To get a field you need to add it to the rule requirements section (see https://www.jetbrains.com/help/youtrack/standalone/2017.3/requirements.html) and reference it inside the rule using `ctx` object (see https://www.jetbrains.com/help/youtrack/standalone/2017.3/context.html).
If you need further assistance, please provide a source code of your workflow rule (maybe its sketch), we'll help to make it work.
Thanks for reply.
This is complete script, it works now:
var entities = require('@jetbrains/youtrack-scripting-api/entities');
exports.rule = entities.Issue.onChange({
title: 'set_issue_build',
guard: function(ctx) {
var pattern = /\[[\w]+_item:\d+\]/;
return ctx.issue.becomesReported && pattern.test(ctx.issue.summary);
},
action: function(ctx) {
var issue = ctx.issue;
var pattern = /\|\*Build\*\|\{color:blue\}(\d+)\{color\}\|/;
if(pattern.test(issue.description))
{
var matches = pattern.exec(issue.description);
var build = ctx['Affected Build'].findValueByName(matches[1]);
if(build != null)
{
issue.fields['Affected Build'].add(build);
}
}
return '';
},
requirements: {
'Affected Build': {
type: entities.OwnedField.fieldType,
name: "Affected Build",
multi: true
}
}
});
Thank you for the shared script :)