Unable to create a scheduled issue

Using a basic workflow construct I was unable to get an issue to be created. I exported the construct to JS and cannot figure out why it is not creating a new issue.

Please advice:

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

var dateTime = require('@jetbrains/youtrack-scripting-api/date-time');


exports.rule = entities.Issue.onSchedule({
  title: "Create VAT Payments",
  cron: '0/10 * * ? * * *',
  search: '',
  action: function(ctx) {
    const logger = new Logger(ctx.traceEnabled);


    // --- #1 createIssue ---
    logger.log("Running \"create-issue\" block", "Proverka DDS");
    const project_0 = ctx.issue.project;
    const user_0 = ctx.currentUser;
    var newIssue_0;

    const createIssueFn_0 = () => {


      const summary = `Proverka DDS`;
      newIssue_0 = new entities.Issue(user_0, project_0, summary);
      logger.log("Issue created", newIssue_0.idReadable);
      newIssue_0.description = `Проверка и плащане необходими да се направят към НАП`;
      newIssue_0.fields["Assignee"] = ctx.AssigneeUser.dippy;
      newIssue_0.fields["Estimation"] = dateTime.toPeriod("3h");
      newIssue_0.fields["Points"] = ctx.PointsState._3;
      newIssue_0.fields["Priority"] = ctx.PriorityEnum.Major;
      newIssue_0.fields["State"] = ctx.StateState.Next;
      newIssue_0.fields["Type"] = ctx.TypeEnum.Task;
    };

    createIssueFn_0();


    // --- #2 linkIssue ---
    const issue_0 = ctx.issue_0;

    function linkIssuesubtaskof_0() {
      return ctx.issue.links["subtask of"].add(issue_0);
    }


    const linkIssueFn_0 = () => {


      linkIssuesubtaskof_0();
    };

    linkIssueFn_0();

  },
  requirements: {
    issue_0: {
      type: entities.Issue,
      id: 'DEMO-20'
    },
    AssigneeUser: {
      name: "Assignee",
      type: entities.User.fieldType,
      dippy: {
        login: "dippy"
      }
    },
    EstimationPeriod: {
      name: "Estimation",
      type: entities.Field.periodType
    },
    PointsState: {
      name: "Points",
      type: entities.State.fieldType,
      _3: {
        name: "3"
      }
    },
    PriorityEnum: {
      name: "Priority",
      type: entities.EnumField.fieldType,
      Major: {
        name: "Major"
      }
    },
    StateState: {
      name: "State",
      type: entities.State.fieldType,
      Next: {
        name: "Next"
      }
    },
    TypeEnum: {
      name: "Type",
      type: entities.EnumField.fieldType,
      Task: {
        name: "Task"
      }
    }
  }
});

function Logger(useDebug = true) {
  return {
    log: (...args) => useDebug && console.log(...args),
    warn: (...args) => useDebug && console.warn(...args),
    error: (...args) => useDebug && console.error(...args)
  }
}

This is the log of the new issue newIssue_0 instance:

{"fields": "{"Priority": {"becomesRemoved": "false",
"isNew": "false",
"$$type": "EnumField",
"toString": function() {},
"toShortString": function() {},
"required": function() {},
"becomes": function() {},
"is": function() {},
"was": function() {},
"isChanged": function() {},
"oldValue": function() {},
"canBeReadBy": function() {},
"canBeWrittenBy": function() {},
"constructor": function() {},
"backgroundColor": "#e6f6cf",
"foregroundColor": "#4da400",
"presentation": "Normal",
"isArchived": "false",
"colorIndex": "17",
"description": "null",
"name": "Normal",
"ordinal": "3"},
"Type": {"becomesRemoved": "false",
"isNew": "false",
"$$type": "EnumField",
"toString": function() {},
"toShortString": function() {},
"required": function() {},
"becomes": function() {},
"is": function() {},
"was": function() {},
"isChanged": function() {},
"oldValue": function() {},
"canBeReadBy": function() {},
"canBeWrittenBy": function() {},
"constructor": function() {},
"backgroundColor": "#fff",
"foregroundColor": "#444",
"presentation": "Bug",
"isArchived": "false",
"colorIndex": "0",
"description": "null",
"name": "Bug",
"ordinal": "0"},
"State": {"becomesRemoved": "false",
"isNew": "false",
"$$type": "State",
"toString": function() {},
"toShortString": function() {},
"required": function() {},
"becomes": function() {},
"is": function() {},
"was": function() {},
"isChanged": function() {},
"oldValue": function() {},
"canBeReadBy": function() {},
"canBeWrittenBy": function() {},
"constructor": function() {},
"isResolved": "false",
"backgroundColor": "#fff",
"foregroundColor": "#444",
"presentation": "Submitted",
"isArchived": "false",
"colorIndex": "0",
"description": "null",
"name": "Submitted",
"ordinal": "0"},
"Subsystem": null,
"Points": {"becomesRemoved": "false",
"isNew": "false",
"$$type": "State",
"toString": function() {},
"toShortString": function() {},
"required": function() {},
"becomes": function() {},
"is": function() {},
"was": function() {},
"isChanged": function() {},
"oldValue": function() {},
"canBeReadBy": function() {},
"canBeWrittenBy": function() {},
"constructor": function() {},
"isResolved": "false",
"backgroundColor": "#fff",
"foregroundColor": "#444",
"presentation": "0",
"isArchived": "false",
"colorIndex": "0",
"description": "null",
"name": "0",
"ordinal": "-1"},
"Fixed in build": null,
"Assignee": null,
"Estimation": null,
"Spent time": null,
"Due Date": null,
"required": function () {
        return functions[key].apply(applyTo, arguments);
      },
"becomes": function () {
        return functions[key].apply(applyTo, arguments);
      },
"is": function () {
        return functions[key].apply(applyTo, arguments);
      },
"was": function () {
        return functions[key].apply(applyTo, arguments);
      },
"isChanged": function () {
        return functions[key].apply(applyTo, arguments);
      },
"oldValue": function () {
        return functions[key].apply(applyTo, arguments);
      },
"canBeReadBy": function () {
        return functions[key].apply(applyTo, arguments);
      },
"canBeWrittenBy": function () {
        return functions[key].apply(applyTo, arguments);
      }}",
"becomesRemoved": "false",
"isNew": "true",
"$$type": "Issue",
"toString": function() {},
"toShortString": function() {},
"required": function() {},
"becomes": function() {},
"is": function() {},
"was": function() {},
"isChanged": function() {},
"oldValue": function() {},
"canBeReadBy": function() {},
"canBeWrittenBy": function() {},
"addAttachment": function() {},
"addComment": function() {},
"addTag": function() {},
"addWorkItem": function() {},
"afterMinutes": function() {},
"applyCommand": function() {},
"becomesReported": "true",
"becomesResolved": "false",
"becomesUnresolved": "false",
"clearAttachments": function() {},
"copy": function() {},
"createCopy": function() {},
"createDraftCopy": function() {},
"currentSlaEnterTime": "null",
"currentSlaPausedTime": "null",
"duplicateRoot": "null",
"editedComments": "[]",
"editedWorkItems": "[]",
"id": "DEMO-39",
"pullRequests": "[]",
"url": "https://los40grandes.youtrack.cloud/issue/DEMO-39",
"vcsChanges": "[]",
"workItems": "[]",
"hasTag": function() {},
"isReported": "false",
"isResolved": "false",
"isStarred": "false",
"isUsingMarkdown": "true",
"isVisibleTo": function() {},
"pauseSLA": function() {},
"removeTag": function() {},
"renderMarkup": function() {},
"resumeSLA": function() {},
"wikify": function() {},
"attachments": "[]",
"boards": "[{"$$type": " Agile", "name": "Demo project Overview"}]",
"comments": "[]",
"created": "1690907340108",
"description": "null",
"ganttCharts": "[]",
"numberInProject": "39",
"permittedGroup": "null",
"permittedGroups": "[]",
"permittedUsers": "[]",
"project": "{"$$type": " Project", "name": "Demo project"}",
"reporter": "{"$$type": " WorkflowUser"}",
"resolved": "null",
"sprints": "[]",
"summary": "Proverka DDS",
"tags": "[]",
"updated": "1690907340108",
"updatedBy": "{"$$type": " WorkflowUser"}",
"voters": "[]",
"votes": "0"}
0
5 comments

Hi. Can you please clarify what your end goal here is and how this looked like in the visual editor (before converting to JS)?

  cron: '0/10 * * ? * * *',
  search: ''

The cron expression does not look correct, and there is no search query used. If the rule were to work on schedule, without a query it would be triggered for every single issue in the instance (which isn't desirable). You can create a dummy issue to use in this search query so it is only triggered once. For general reference on scheduled workflow rules, please see our Developer Portal documentation: On-schedule Rules.

0

Hello Stanislav Dubin. My goal with this is to create a recurring issue which is a sub-task of an another issue which would be an Epic, containing all of the tasks of a certain type. The CRON schedule was generated by https://www.freeformatter.com/cron-expression-generator-quartz.html as a recommendation from Youtrack and it is an example to test the rule actually works, It is supposed to run every 10 seconds. An example Construct looks like this:

I am looking for a way to automate similar monthly tasks that can contain differences and be able to edit them, without loosing track of the previous ones, which seems thus far as a separate issue has been the best approach.

0

The cron expression Freeformatter produces to represent every 10 seconds (starting at 0) is this:

0/10 0 0 ? * * *

On-schedule rules are applied to every issue that fits the criteria. Therefore, it would be wise to use a query that returns only the issues you need this rule to apply to. In your case, you can have just one issue (any will do). E.g., like so:

0

Thank you for the suggestion. I attempted to link to another issue as suggested and now I am getting an HTTP error response code of 500 with the following cryptic message in the response body when I try to fill the filter field and It seems I am unable to select any issue under the filter

XHRPOST
https://los40grandes.youtrack.cloud/api/search/assist?fields=title,caret,query,styleRanges(length,start,style,title),suggestions(description,group,icon,option,prefix,suffix,className,matchingStart,matchingEnd,caret,completionStart,completionEnd)
[HTTP/2 500 Internal Server Error 62ms]

{"error":"server_error","error_description":"unknown error"}

 

0

We'd like to take a closer look at this problem on your Cloud instance. Please create a private ticket via our form: https://jb.gg/ytsup.

0

Please sign in to leave a comment.