Workflow change issue State from "To Do" to "In progress" on adding spent time



I wrote following script:

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

exports.rule = entities.Issue.onChange({
title: 'In_progress',
guard: function(ctx) {
var workItemSize = ctx.issue.workItems.size;
var iterator1 = ctx.issue.workItems.values();

var date = new Date();
var stateName_ =;
if (stateName_ == "To Do") {
if(workItemSize > 0) {
return true;
return false;
action: function(ctx) {
var issue = ctx.issue;
workflow.message(workflow.i18n('Our case'));
issue.fields.State = 'In Progress';
requirements: {
State: {
name: 'State',
type: entities.EnumField.fieldType


That change issue state from "To Do" to "In progress" on any event in a case of at least one work log exist.

How to modify it to make this only on adding spent events?

Cuz now I am unable to change issue state back to "To Do".

1 comment
Comment actions Permalink
Official comment


I am sorry for the delay. Please use ctx.issue.workItems.added.isNotEmpty() to check if any work items have been added in current transaction. 

Thank you. 

Please sign in to leave a comment.