Script Validation Checker

Vando Goncalves _e-Core_ January 13, 2020

Hi guys, how are you doing.

I know this can be made using a condition, but, I'd like to do it using validator so a warning message can be shown.

That being said, here it goes:

I want to allow the issue transition only if the subtasks from that issue are all resolved or in a certain status.

How I'm trying to achieve this?

Workflow Validator > Script Runner Script

This is the Script:

def allSubtasks = get("/rest/api/2/search")
.queryString("jql", "parent=${issue.key}")
.asObject(Map)
.body
.issues as List<Map>

def allowClose = true

def subResolution = allSubtasks?.fields?.resolution

subResolution.each{ sub->
if (!sub){
allowClose = false
}
}

return allowClose

 

Running this code (with some customizations, to get issue) on the Script Console, it returns correctly true, when all subtasks are with a resolution, and false when not.

But, when I add it to the Validator, seems to be always false, as it not allow me to perform the transition.

1 answer

1 accepted

2 votes
Answer accepted
Kristian Walker _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.
January 14, 2020

Hi Vando,

Thank you for your question.

I can confirm that validators in ScriptRunner for Jira Cloud use the Jira Expression Framework as described in the Atlassian documentation here which means you cannot write normal groovy code to write the validator expression.

We have created the Knowledge Base article located here which explains in more detail how validators work and how to check the syntax required to write them and you will be able to use this as a reference guide to help you create the validator that you require.

I can also confirm that we have collated some example validators here and one of the examples shows how to only allow an issue to be transitioned when all subtasks, are in the In Progress status and this will be a useful reference to help you to create the validator expression which you require.

I hope this information helps.

Regards,

Kristian

Vando Goncalves _e-Core_ January 14, 2020

Thanks a lot Kristian!

Kristian Walker _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.
January 14, 2020

Hi Vando,

You are welcome.

Regards,

Kristian

cgadade March 17, 2020

Hi @Kristian Walker _Adaptavist_ ,

Yes , Scriptrunner jira cloud validator uses only jira expressions ,

  Can u please help me to write Jira expression to check assignee is from specified group or not.I am trying following code :

['groupname' : 'administrators'].includes[issue.assignee.accountId]

Please help me.above expression does not return true still assignee is from administrators

group.

Kristian Walker _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.
March 18, 2020

Hi Cgadade,

I can confirm that validators inside of ScriptRunner for Jira Cloud are defined using the Jira Expression Framework as documented in the Atlassian API documentation page located here or in the documentation page located here which explains how to add in a new validator to your workflow.

We can confirm that when viewing the Jira Expression Framework API documentation page linked above you can navigate to the Context variables section which shows what variables are provided by this framework that can be used to create the expression.  If you then click on one of the variables it will show all the properties that can be called on the variable for the expression such as for the issue variable as shown here.

Viewing the Context variables section of the Jira Expression Framework API documentation I can confirm that there is a user property as described here which has the groups property below it and this is what you will need to check against to check if a user is in a certain group.

Please note I cannot give you an exact condition as I do not have a condition to hand to achieve your requirement but you can use the information above to see how to check the Jira Expression Framework API documentation to see what properties can be used to create validators.

Regards,

Kristian

Suggest an answer

Log in or Sign up to answer