Notify When Dependency Resolved
This workflow sends notification to the assignee of an issue when a dependant issue is resolved.
Name | @jetbrains/youtrack-workflow-notify-when-dependency-resolved |
---|---|
Auto-attached | no |
Modules | Notify assignee when an issue linked as "required for" is resolved (on-change rule) |
Use Case
This workflow lets a user know when one of the issues that they are waiting on is resolved.
Modules
This rule checks the status of any issues that are linked as required for. If a linked issue is resolved, the assignee of the blocked issue is notified.
Notify assignee when an issue linked as "required for" is resolved
const entities = require('@jetbrains/youtrack-scripting-api/entities');
const workflow = require('@jetbrains/youtrack-scripting-api/workflow');
exports.rule = entities.Issue.onChange({
title: 'Notify assignee when an issue linked as "required for" is resolved',
guard: (ctx) => {
const issue = ctx.issue;
return issue.fields.isChanged(ctx.State) && issue.fields.State && issue.fields.State.isResolved &&
(!issue.fields.oldValue(ctx.State) || !issue.fields.oldValue(ctx.State).isResolved);
},
action: (ctx) => {
if (ctx.issue.links['is required for'].isNotEmpty()) {
const getLinkToIssue = function(i) {
return '<a href="' + i.url + '">' + i.id + '</a> ' +
'<a href="' + i.url + '">' + i.summary + '</a>';
};
ctx.issue.links['is required for'].forEach(function(dependent) {
const assignee = dependent.fields.Assignee;
const state = dependent.fields.State;
if (assignee && assignee.login !== ctx.currentUser.login && (!state || !state.isResolved)) {
const subject = '[Youtrack, Required issue is resolved]';
const body = [
'Dear assignee of {0}.', getLinkToIssue(ctx.issue),
'<br>',
'I\'m pleased to inform you that the issue required for your work - ' +
'{0} - just has been resolved.', getLinkToIssue(dependent),
'<p style="color: gray; font-size: 12px; margin-top: 1em; border-top: 1px solid #D4D5D6">',
'Sincerely yours, YouTrack',
'</p>'
].join('\n');
assignee.notify(subject, body, true);
}
});
}
},
requirements: {
State: {
type: entities.State.fieldType
},
Assignee: {
type: entities.User.fieldType
},
Depend: {
type: entities.IssueLinkPrototype,
name: 'Depend',
outward: 'is required for',
inward: 'depends on'
}
}
});
warning
Localized MessagesThe original workflow script provided by YouTrack uses the
workflow.i18n
function. This is an internal function that is only meant to be used to reference localized message strings. To ensure that you can copy and customize this workflow code, we have removed this function from the sample. If you are editing the default workflow and want to customize any message text, we recommend that you remove these functions from your code as well.To learn more about localized messages in workflows, see Localized Workflow Messages.