我想阻止 YouTrack 中的用户修改或添加过去的工作项。他们应该只在当天添加/修改工作项目。
在 YouTrack 工作流程中,我可以检测更改的花费时间事件并阻止用户添加工作项。但我想在用户在 JavaScript 工作流中修改工作项时收到一个事件。这是我的代码:
var entities = require('@jetbrains/youtrack-scripting-api/entities');
var workflow = require('@jetbrains/youtrack-scripting-api/workflow');
exports.rule = entities.Issue.onChange({
title: workflow.i18n('Disable editing workitems'),
guard: function(ctx) {
return ctx.issue.fields.isChanged(ctx.ST);
},
action: function(ctx) {
workflow.check(ctx.issue.workItems.added.isEmpty(), workflow.i18n('You can add/modify workitems only in current day.'));
},
requirements: {
ST: {
type: entities.Field.periodType,
name: 'Spent Time'
}
}
});
省略日期时间条件...
最佳答案
不确定它是否仍然相关,但我有完整的示例:
/**
* This is a template for an on-change rule. This rule defines what
* happens when a change is applied to an issue.
*
* For details, read the Quick Start Guide:
* https://www.jetbrains.com/help/youtrack/server/2022.2/Quick-Start-Guide-Workflows-JS.html
*/
const entities = require('@jetbrains/youtrack-scripting-api/entities');
const workflow = require('@jetbrains/youtrack-scripting-api/workflow');
exports.rule = entities.Issue.onChange({
title: 'Prevent-workitem-updates-past',
guard: (ctx) => {
const issue = ctx.issue;
const fs = issue.fields;
// NOT using issue.workItems.added.isEmpty() , because we also want to detect EDITS as well as ADDS to the WorkItems array.
return fs.isChanged(ctx.ST) && !issue.becomesReported;
},
action: (ctx) => {
const issue = ctx.issue;
function checkWorkItemDate(currentWorkItem, currentEpochTimeStamp){
workflow.check(currentWorkItem.date == currentEpochTimeStamp, workflow.i18n('You can add/modify workitems only in current day.'));
}
//const splittedDate = new Date().toISOString().slice(0, 10).split('-');
//const currentEpoch = new Date(splittedDate[0], splittedDate[1] - 1, splittedDate[2]).valueOf();
const currentDate = new Date();
const currentEpoch = new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()).valueOf();
// Check newly added elements
issue.workItems.added.forEach(workItem => {
checkWorkItemDate(workItem, currentEpoch);
});
// Check edited elements
issue.editedWorkItems.forEach(workItem => {
checkWorkItemDate(workItem, currentEpoch);
});
workflow.check(true);
},
requirements: {
ST: {
type: entities.Field.periodType,
name: 'Spent Time'
}
}
});
关于javascript - 如何禁用 YouTrack 工作流程中修改工作项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48766799/