Troubleshooting YouTrack Workflow Error: Status Update from 'Done' to 'Closed
Dear YouTrack Community,
I’ve created a JavaScript workflow using AI that updates an issue’s status automatically. Specifically, when an issue’s status is set to “Done,” it should transition to “Closed” after 10 days. However, after saving the workflow and assigning it to my test project, I encountered the following error:
"Add 'Status' to the set of values for the State field. This problem must be resolved manually."
I’ve already verified that my project has a field named “Status” of the State type, and it includes both “Done” and “Closed” as values—spelled correctly, with no extra spaces. Could someone help me understand why this error is occurring and how to resolve it?
Thank you very much in advance for your assistance!
Best regards,
/**
* This workflow automatically changes the status of an issue from "Done"
* to "Closed" after 10 days.
*
* For details, read the Quick Start Guide:
* https://www.jetbrains.com/help/youtrack/devportal/Quick-Start-Guide-Workflows-JS.html
*/
const entities = require('@jetbrains/youtrack-scripting-api/entities');
exports.rule = entities.Issue.onChange({
// Title of the workflow rule
title: 'Auto-close issue after 10 days',
// Condition: Trigger only if the issue status is changed to "Done"
guard: (ctx) => {
return ctx.issue.fields.Status.name === 'Done';
},
action: (ctx) => {
const issue = ctx.issue;
// Delay execution for 10 days (10 * 24 * 60 * 60 * 1000 ms)
ctx.schedule(() => {
if (issue.fields.Status.name === 'Done') { // Ensure it's still in "Done"
issue.fields.Status = ctx.requirements.Status.Closed;
}
}, 10 * 24 * 60 * 60 * 1000); // 10 days delay
},
requirements: { // ✅ Correct placement of "requirements"
Status: {
type: entities.State, // Ensure it matches your field type
values: {
Done: { name: 'Done' },
Closed: { name: 'Closed' }
}
}
}
});
Please sign in to leave a comment.
Hello Mickeychen4728
Please change this line:
type: entities.State,
To this:
type: entities.State.fieldType,
That should do the trick.
Hi Alisa Kasyanova ,
thx very much for helping. I changed as you described. And now i can successfully saved the script.
But another problem now is i cannot update any field in the issue in the project (attached with the script).
Any idea why and how to fix?
Error: Couldn't update issue field. The close_issue_after_10_days/close_issue rule threw an exception when processing the following issue: TPF-2
Thx in advance!
Mickeychen4728 please check the workflow editor's console, it should show a more detailed error. What does it say?