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

Begoña Bonet July 9, 2015

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

5 answers

1 vote
teilor_soares
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.
July 9, 2015

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

0 votes
Marc Minten _EVS_
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.
July 9, 2015

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
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.
July 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.  

0 votes
Begoña Bonet July 9, 2015

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

Udo Brand
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.
July 9, 2015

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.

Marc Minten _EVS_
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.
July 22, 2016

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 ?

0 votes
Udo Brand
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.
July 9, 2015

Suggest an answer

Log in or Sign up to answer