Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Excerpt

A workflow validator that is based on the result of a Jira expression.

 If

  

If the Jira expression returns false, a validation error message will be displayed.

 

 This can be used to test or compare issue fields, to test linked issues, to check for open Sprints, etc.

To add the '

Scripted (Jira expression)

Build-your-own (scripted) Validator' to a transition:

  1. Click Edit for the workflow that has the transition you wish to configure the condition on.

  2. In the Workflow Designer, select the transition.

  3. Click on Validations in the properties panel.

  4. Click on 

Add validation
  1. Add validation.

  2. Select 

Scripted (Jira expression) Validator 
  1. Build-your-own (scripted) Validator from the list of

conditions
  1. validators.

  2. Click on Add

 to
  1.  to add the validator on the transition.


Image Removed
  1. Input a Jira expression in the Jira expression field.

  2. Input a message in the Error message field to display if the configured conditions are not satisfied.

  1. For information on how to write a 'Jira expression' see How to insert information using Jira expressions.

  2. Click on Add to add the condition to the transition.

panel
Note

On the Service Management portal view of a request, the customer will not see the Error message when the validator fails. This is due to a known limitation (JSDCLOUD-5853) with Atlassian.

Related links

:

Info
Refer to the cases for validators page for use .For information on how to write a Jira expression, see How to insert information using Jira expressions.

When you add this validator to a transition and trigger the transition, the add-on checks the result of the Jira expression. If it returns true the validation will pass. If it

returns 

returns false or any non-boolean value, a validation error message is displayed.


Use case

A typical use of this workflow validator is to validate that the field of the issue has a specific value or the current user belongs to a specific group during the transition. Consider a use case where you want to block the user from triggering the “Approve” transition when the current user is not in the “Approvers” field. To configure this:

  1. Add the “Build-your-own (scripted) validator” to the “Approve” transition

  2. Input the following code under “Jira Expression”

    Code Block
    !! issue.customfield_10002 && issue.customfield_10002.some(it => it == user)

Another use of this validator is to validate the comment added during the transition. Jira expressions do not facilitate a context variable to get the comment added during the transition. But you can access the comment on the transition screen with a workaround. Consider a use case where you want to block the user from rejecting the “Bug” without a comment with atleast 10 characters. To configure this:

  1. Add the “Build-your-own (scripted) validator” to the “Approve” transition

  2. Input the following code under “Jira Expression”

  3. Code Block
    issue.comments.some(comment => !comment.id && comment.body.plainText.length > 10)

This basically tests whether there is a comment that has no ID (and therefore is new) and whose body length is > 10.