Prompt user to add links

Hi there,

I'm trying to create a custom action using the Javascript Workflow that creates an issue based on the current issue and then subsequently prompts the user to add some links to the new issue (that aren't to the initial issue).

I can successfully create the new issue, but then when I tried to use the required method on it, it tried to apply the link to the initial issue. So I then separated the workflows, one that just creates the new issue, this works by itself, and then another issue to prompt the user to create the links when the new issue is created. I'm still trying to use th required method but it brings up the apply command dialog box and it says it's applying it to "undefined". It seems to be preventing the issue creation and also not allowing me to add the link so it can be created. What am I missing?

Cheers

 

0
2 comments

For reference this is the workflow as it currently stands.

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

exports.rule = entities.Issue.onChange({
  // TODO: give the rule a human-readable title
  title: 'On-test-run-create',
  guard: (ctx) => {
    var issue = ctx.issue;
    return issue.Type && (issue.Type.name == ctx.Type.TestRun.name) && issue.becomesReported;
  },
  action: (ctx) => {
    const issue = ctx.issue;
    
    issue.required(ctx.Execution.inward, "Please assign test case or test suite to test run");
  },
  requirements: {
   Execution: {
     name: 'Execution',
      type: entities.IssueLinkPrototype,
      outward: 'Execution',
      inward: 'Assigned test case or test suite',

    },
    Tests: {
      name: 'Tests',
      type: entities.IssueLinkPrototype,
      outward: 'is tested by',
      inward: 'tests'
      },
    Type: {
      type: entities.EnumField.fieldType,
      TestExecution: {
        name: "Test Case Execution"
      },
      TestRun: {
        name: "Test Run"
      },
      TestCase: {
        name: "Test Case"
      },
      TestSuite: {
        name: "Test Suite"
      }
    }
  }
});
0

Hi,

Thank you for reaching out. I'd recommend referring to ctx.issue.links['parent for'] entity to check if there are any subtasks added. The workflow.check() method can revert the operation if there are none.

So you can use the following code instead of issue.required:

workflow.check(ctx.issue.links['parent for'].isNotEmpty(),'please create a linked issue');

It will revert the operation if the issue has no subtasks and display the corresponding message. Will it work for you? 

0

Please sign in to leave a comment.