Forums

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

ScriptRunner for Jira set condition on workflow validator "Require comment on transition"

Ardjan Moerkerken
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 25, 2018

We are using workflow in combination with Scriptrunner to set a validator.The validator we are using is "Require comment on transition" We want this validator to be used for anyone except one user.


The reason for the above is that we are using a plugin to bi-sync two instances of Jira by field, workflow and thus validator. The plugin seems to work but fails at the moment we activate a workflow where the validator is active. 

If we can add a condition on the script Require comment on transition(wich is possible on Simple scripted validator but not on comment on transition) like if the user is not x than the validator is enforced we would would be gratefull

 

If there is a other way, we would also be gratefull

2 answers

1 accepted

2 votes
Answer accepted
Carmen Creswell [Adaptavist]
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 25, 2018

Hi Ardjan!

If you use a Custom Scripted Field, you can use this script: 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.workflow.WorkflowActionsBean
import com.opensymphony.workflow.InvalidInputException
import com.opensymphony.workflow.loader.WorkflowDescriptor

def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser.name

if (currentUser != "admin") {

def comment = transientVars.get("comment")
if (!comment) {

def workflowActionsBean = new WorkflowActionsBean()

def workflowDescriptor = transientVars.get("descriptor") as WorkflowDescriptor
def actionDescriptor = workflowDescriptor.getAction(transientVars.get("actionId") as Integer)
if (!workflowActionsBean.getFieldScreenForView(actionDescriptor)) {
throw new InvalidInputException("You need to provide a comment for this transition but no screen is in use." +
" Contact your administrator.")
} else {
throw new InvalidInputException("comment", "Please provide a comment for this transition")
}
}
}
Carmen Creswell [Adaptavist]
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 25, 2018

You'll just have to change the "admin" to the user you want to exclude from being required to make comments. 

Ardjan Moerkerken
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, 2018

Thank you very much, i can confirm this solution works!

Your excellent premium response is higly appreciated!

Carmen Creswell [Adaptavist]
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, 2018

You're welcome! Feel free to mark this answer as accepted if it solved your problem! 

1 vote
Gezim Shehu [Communardo]
Community Champion
April 25, 2018

Hi,

 

Do you have AMUTILS (free addon)?

Has the below option which I think would work for you.

 

 

comment validator.PNG

Suggest an answer

Log in or Sign up to answer