Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get details for validators via groovy

arama mihai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 26, 2021

Hello,

 

I have found thanks to this thread : https://community.atlassian.com/t5/Jira-questions/How-to-execute-all-the-validators-defined-in-the-Workflow/qaq-p/892011

that I can use the "getValidators()" method to the the validators associated to a transition. However, it returns me the validator object (I assume), and I want the name and the description of what it does.

Example: 

 

allStatuses.each { status -> 
def relatedActions = eachWorkflowObject.getLinkedStep(status).getActions()
log.warn("For the status " + status.name + " the available transitions are: " + relatedActions)

relatedActions.each { it ->
def validators = it.getValidators()
log.warn("For the transition " + it + " the validators are: " + validators)

}

For the transition Close Issue (resolveissue) the validators are: [com.opensymphony.workflow.loader.ValidatorDescriptor@3e54be25]

That;s great, but I would love to get information like: 

For the transition Close Issue (resolveissue) the validators are:  resolution field is mandatory. 

I tried with it.getValidators()*.name , or validators.name and it is blank.

What are the properties accepted by a validator, or the functions that can be used to get a readable description of the validator?

 

Thank you! 

2 answers

0 votes
Hans Pesata
Contributor
July 20, 2023

Hi!

Thanks for the very valid information within this post!

I would also need to iterate the "postfunctions", but using

transitionProperties.postfunctions.each

doesn't work.

Any idea how to get the postfunctions ?

Thanx in advance!

Regards, Hans

0 votes
Etiennealexh
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 26, 2021

Just go to the help page and find information 

arama mihai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 26, 2021

Hi @Etiennealexh ,

Not sure what help page information you are referring to. I searched the https://docs.atlassian.com/software/jira/docs , but couldn't find what I needed. If you know where that info would be, that would be helpful :)

Ken McClean
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 31, 2023

You were really close! You can use dot notation to get the information you're after. 

From the script below, you can see that when we get to transitionProperties, i.e. the properties for each transition, we can access the validators for each by simply creating a closure using transitionProperties.validators.each

Within that closure, we see that we can further access the arguments of the validator by calling valid.properties.args.  This results in output like so:

{nullallowed=true, permissionKey=ADMINISTER_PROJECTS, vars.key=<key>, class.name=com.atlassian.jira.workflow.validator.UserPermissionValidator}

Clearly the args would be different for every different kind of validator, but that should get you close.

 

import com.atlassian.jira.workflow.WorkflowManager
import com.atlassian.jira.component.ComponentAccessor

def workflowManager = ComponentAccessor.getComponent(WorkflowManager)
def wf = workflowManager.getWorkflow("<workflow name>")
//wf is the workflow itself

def statuses = wf.getLinkedStatusObjects()
//statuses are the statuses available to that workflow

statuses.each {
status ->
//For each status associated with the workflow

def relatedActions = wf.getLinkedStep(status).getActions()
//relatedActions is the set of actions (transitions) associated with each status
log.warn("For the status " + status.name + " the available transitions are: " + relatedActions)

relatedActions.each {
it ->
//For each related transition, we need the validators associated with the

def transitionProperties = it.properties

transitionProperties.validators.each {
valid ->

log.warn(valid.properties.args)
}
}
}



Like Sergiienko Volodymyr likes this
Hans Pesata
Contributor
July 20, 2023

Hi!

Thanks for the very valid information within this post!

I would also need to iterate the "postfunctions", but using

transitionProperties.postfunctions.each

doesn't work.

Any idea how to get the postfunctions ?

Thanx in advance!

Regards, Hans

Suggest an answer

Log in or Sign up to answer