Using scriptrunner condition in JIRA workflow to validate and restrict transition

Arti Patil December 31, 2024

Hello, 
i am looking for adding workflow condition using scriptrunner validator in jira. 

use case - custom field A and parent field will decide nature of the error message. Both are drop down field.

  1.  if custom field A == option 1 && parent == Null >> show error
  2.  if custom field A == option 1 && parent != Null >> pass
  3. if custom field A == option 2 && parent == Null >> pass
  4. if custom field A == option 2 && parent != Null >> show error

i am trying below condition but it is not working as is

 

if(issue.customfield_.value == "option 1" && issue.parent != null){
    return true
}else if(issue.customfield_.value != "option 1" && issue.parent != null){
    return true
}
else {
    return  false
}


it is not working for conditions when custom field value != option 1.
any one help with logic i am missing here. Thanks

2 answers

1 vote
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 31, 2024

Hi @Arti Patil

I can confirm the approach you are trying will not work.

The validator for Jira cloud doesn't work the same as it doesn't in Jira DC / Server.

You will need to use Expressions for Jira Cloud. As explicitly mentioned in this ScriptRunner for Jira Cloud documentation, Jira Cloud Expressions do not support if/else conditions.

I suggest using ScriptRunner's Expression Generator to create your expressions. Once you have created your Expression using the Expression Generator, you can copy the code and add it to your validator.

Alternatively,  you can also use the in-built Expression Builder in the validator as shown in the screenshots below:-

image1.png

image2.png

I hope this helps. :-)

Thank you and Kind regards,
Ram

0 votes
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 31, 2024

Hi @Arti Patil 

I am not sure if I get it right but I trust the below code will help you


def customFieldA = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_XXXXX"))
def parentIssue = issue.getParentObject()

if (customFieldA == "option 1" && parentIssue == null) {
return false // "Parent issue is required when Custom Field A is Option 1"
} else if (customFieldA == "option 2" && parentIssue != null) {
return false // "Parent issue must be null when Custom Field A is Option 2"
}

return true

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
PREMIUM
PERMISSIONS LEVEL
Product Admin
TAGS
AUG Leaders

Atlassian Community Events