Send Slack notification after issue creation

Answered

Hello,

We have a workflow that send a Slack notification after an issue is created. It was working perfectly until we decided to create another workflow for mandatory fields.

If we create an issue and forget to fill a field, when we click on create issue we display a message to the user, but unfortunately the Slack notification is send.

I think it is linked to the issue.becomesReported that triggers even if the issue is not created

We use YouTrack 2017.3 and here are the 2 workflows :

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

exports.rule = entities.Issue.onChange({
title: 'Choose Category when new issue is created',
guard: function(ctx) {
var issue = ctx.issue;
return issue.becomesReported &&
!issue.fields.Category && ctx.issue.fields.Type.name != 'Epic';
},
action: function(ctx) {
ctx.issue.fields.required(ctx.Category, 'Please choose issue Category before submitting');
},
requirements: {
Category: {
type: entities.EnumField.fieldType
}
}
});


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

exports.rule = entities.Issue.onChange({
title: 'Send notification when an issue is created',
guard: function(ctx) {
var issue = ctx.issue;
return issue.becomesReported && issue.isReported;
},
action: function(ctx) {
var issue = ctx.issue;

//Slack message
},
requirements: {
State: {
type: entities.State.fieldType
},
Priority: {
type: entities.EnumField.fieldType
}
}
});

Can you give us a hand on this ?

Thanks in advance
Regards

0
1 comment
Avatar
Permanently deleted user

Hi,

The problem here is that you can never rely on the order of workflow rules execution in case of they can be executed in any order (as in this case). The most reliable solution here is to embed the mandatory fields logic into the Slack rule itself: namely, you check that all the required fields are in place and only then send a notification to Slack.

0

Please sign in to leave a comment.