I'm trying to automatically update an estimated issue duration using a numeric field called 'Estimate'.
I can access the start date and due date and take their difference in days (the intended estimate), but I am not able to update the Estimate field with this value. The error indicated is "Cannot set value to custom field Estimation", which is strangely phrased - is this not a supported functionality, or is this indicating some conversion of the value needs to take place, or something else?
/**
* Whenever a due date is changed, if there is a start date present, autofill
* the estimation field as the numerical difference between two dates in days
*/
const entities = require('@jetbrains/youtrack-scripting-api/entities');
exports.rule = entities.Issue.onChange({
title: 'Due-date-set',
guard: (ctx) => {
const issue = ctx.issue;
return issue.isChanged('Due Date');
},
action: (ctx) => {
const issue = ctx.issue;
const diff = (issue.fields.DueDate - issue.fields.StartDate)/86400/1000;
issue.fields.Estimation = diff;
},
requirements: {
DueDate: {
type: entities.Field.dateType,
name: 'Due Date'
},
StartDate: {
type: entities.Field.dateType,
name: 'Start Date'
}
}
});