Where can I find some examples to define a script validator using script runner?

Hi,

I need to define a script validator and I have no experience on it. Where can I find examples or manuals to do that?

Thanks in advance

 

Begoña

4 answers

Not sure if is that what you are looking for, but there is a few examples in the link below:

https://jamieechlin.atlassian.net/wiki/display/GRV/Validators

Cheers!
Teilor

Following these examples I've witten a script groovy only with the following code:

 

import com.opensymphony.workflow.InvalidInputException
import org.apache.log4j.Category

log.info("START - VALIDATOR"); 
log = Category.getInstance("com.onresolve.jira.groovy.example.testValidator")
invalidInputException = new InvalidInputException("Validation failure")
log.info("END - VALIDATOR");

 

I've defined a Validation "Script validator" in "Create" action where this script is invoked but when I launch "create issue" I can create issues with any problem. 

I'm sure I haven't understood how Script validators works...... any help?

Thanks in advance

 

Begoña

It's almost identical to the simple example in the link Teilor and me provided. Honestly, I don't see why it is not working.

Hi, sorry was in holiday. Your script seems to be ok to me. Did you find any errors in the log file ? Did you find the logging info ?

Of course depends how complex the validations are, but here a simple example (for issue type 'Bug' the field AffectedVersion should be filled:

import com.atlassian.jira.issue.Issue 
import com.opensymphony.workflow.InvalidInputException
Issue myIssue = issue
if (myIssue.getIssueTypeObject().getName() == "Bug") { 
	if (! myIssue.getAffectedVersions().size()) { 
		invalidInputException = new InvalidInputException("versions", "Affects Version/s is required in this context.")     
	} 
}

Hi @Marc Minten (EVS), 
I need help with something similar as well.

I have a workflow with multiple projects in it.
I want to make a field required in one of the Projects. (lets say ABC)

I want to make the Sprint field required in this project ABC when the user moves the issue from "Submitted to Assigned" state.

I've tried doing it by modifying your code but it's not working.
Could you help me out?
I'd appreciate the help. Many thanks.  

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,656 views 18 21
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you