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.")     
	} 
}
Tayyab Bashir Community Champion Jul 14, 2016

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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

2,889 views 12 18
Join discussion

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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot