[RESOLVED] How to avoid running script for parent Issue?
Hello,
I have a script and it is very simple. It checks if the current user is an Assignee. The problem is that the script is run both in the current Issue and in the parent Issue if the current Issue is a Subtask.
How to avoid running script for parent Issue? Thanks.
const entities = require('@jetbrains/youtrack-scripting-api/entities');
const workflow = require('@jetbrains/youtrack-scripting-api/workflow');
const r = require('../lib/check-rights');
exports.rule = entities.Issue.onChange({
title: 'Estimation field restrictions',
guard: (ctx) => {
return ctx.issue.fields.isChanged(ctx.Estimation);
},
action: (ctx) => {
if (ctx.issue.fields.Assignee !== null) {
workflow.check(r.check(ctx), "Can't touch this!");
}
},
requirements: {
Estimation: { type: entities.Field.periodType, name: 'Estimation' }
}
});
Please sign in to leave a comment.
Hi, the problem here most likely comes from the fact that estimations in subtasks are summed up to produce the parent issue estimation (so whenever you change it in a subtask, that in turn triggers a change in the parent task).
If you don't expect the parent task to have any own parents, you can modify the guard section like so:
This will help to check if the issue has a parent, and only in that case will the action in the script execute.
It may have own parent.
The idea is to allow the Assignee to change the time in the "Estimation" field in the subtask, but not allow it to be done in the parent task directly by changing the field. Because the parent task has a different Assignee. At the same time, without limiting the number of parent tasks.
I found a solution. I am using a flag. First I check if the user has rights in the current task, and then I check the subtasks. If there is a subtask where the field has changed in the current transaction, then the user had rights there and I change the flag to allow changes. Works regardless of the nesting of subtasks.