How do you know that an issue "enters" a particular board ?

Hi

I need to do a particular action each time an issue is affected to a particular agile board.
In OnChange rule, I can't figure out how to check that. Documentation is really poor on detailed stuff like that. I didn't find any existing rule that implements that either.

Many thanks.

Laurent

0
8 comments
Official comment

Hello,

It is possible to implement this task by checking if the issue's sprint has been changed. For example:

var entities = require('@jetbrains/youtrack-scripting-api/entities');
var workflow = require('@jetbrains/youtrack-scripting-api/workflow');
exports.rule = entities.Issue.onChange({
title: 'Sprints-test',
guard: function(ctx) {
    return ctx.issue.sprints.added.isNotEmpty();
},
action: function(ctx) {
    workflow.message('Sprint is added: '+ctx.issue.sprints.added.get(0).name);
},
requirements: {
     // TODO: add requirements
}
});

I hope it will be helpful. Should you have any further questions, feel free to contact us.

 

Hello

thanks for your help.
I tried something like that, but in my kanban board, when i add an issue, the line :

console.log(ctx.issue.sprints.added);

shows an empty array : (sprints are disabled in my kanban board)

laurent.polese@77.159.203.132 26 févr. 2019 18:02
[]

so I can't find how to know that the issue has been added.

 

I'm able to retrieve the board like that :

var PoBoard = entities.Agile.findByName('PO V2 Kanban').first();
console.log(PoBoard);

Which gives me :

laurent.polese@77.159.203.132 26 févr. 2019 18:02
{"becomesRemoved": "false",
"isNew": "false",
"$$type": "Agile",
"toString": function() {},
"toShortString": function() {},
"required": function() {},
"becomes": function() {},
"isChanged": function() {},
"oldValue": function() {},
"canBeReadBy": function() {},
"canBeWrittenBy": function() {},
"findSprintByName": function() {},
"author": "{"$$type": " User", "login": "laurent.polese"}",
"getIssueSprints": function() {},
"name": "PO V2 Kanban",
"sprints": "[{"$$type": " Sprint", "name": "Premier sprint"}]"}

But from there I'm stuck. I can't find relations between issues and boards (not sprints), and even less detect changes in those relations.

Many thanks for your help.

Laurent

0

Would you please provide me with a code of your workflow? Also, would you please clarify which actions you are preforming in your issue?

0

Sure, here is the full code (I let the console calls to let you know what was tested) :

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

exports.rule = entities.Issue.onChange({
title: 'Ajouter le Récit au Tableau PO l\'ajoute ainsi que les Tâches au Tableau dev',
guard: function(ctx) {
console.log('in guard');
if (ctx.issue.fields.Type.name != 'User Story') {
console.log('not a story');
return false;
}
var PoBoard = entities.Agile.findByName('PO V2 Kanban').first();
console.log(PoBoard);
var goForIt = false;
console.log (ctx.issue.sprints);
console.log (ctx.issue.fields.Boards);
console.log(ctx.issue.sprints.added);
ctx.issue.sprints.forEach(function(sprint) {
console.log('found a sprint');
if (sprint.agile.name == 'PO V2 Kanban') {
goForIt = true;
}
});

if (goForIt) {
ctx.issue.oldValue('sprints').forEach(function(oldSprint) {
if (oldSprint.agile.name == 'PO V2 Kanban') {
goForIt = false;
}
});
}
return goForIt;
},
action: function(ctx) {
workflow.message('in action !');
var issue = ctx.issue;
var subTasks = issue.links['parent for'];
if (subTasks) {
subTasks.forEach(function(subTask) {
subTask.applyCommand('Add board Dev V2 Kanban');
workflow.message (subTask.id + ' - ' + subTask.summary + ' - automatiquement ajouté au tableau dev Kanban');
});
}
issue.applyCommand('Add board Dev V2 Kanban');
workflow.message (issue.id + ' - ' + issue.summary + ' - automatiquement ajouté au tableau dev Kanban');
},
requirements: {
}
});

I'm testing this with removing then adding a User Story to the board named "PO V2 Kanban".

The issue enters the onChange rule, but the line

console.log (ctx.issue.sprints);

shows

[]

As does the line

console.log(ctx.issue.sprints.added);

Thanks for your help.

Laurent

0

Hello Laurent,

Thank you for the attached code. This issue seems to be strange. Would you please clarify which version of YouTrack (inCloud or Standalone) you are using and specify the build number? Your cooperation is greatly appreciated. 

 

0

Hello Oleg,

we're using Youtrack InCloud.

Thanks
Laurent

0

Thank you for the clarification. Would you please make sure that sprints are enabled for your board?

0

Hello,

I am afraid, for now YouTrack workflow does not allow getting issue's boards. It is only possible to get sprints.
Please feel free to vote for this feature request: https://youtrack.jetbrains.com/issue/JT-51898 to increase its priority and to receive the updates.

0

Please sign in to leave a comment.