Error in Groovy simple scripted Validator - JIRA 5.2

mehala n
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.
August 5, 2013

To validate issue subtype we have a simple scripted Validator.It was wrking fine in JIRA 4.2.But throws error in 5.2 .10 version.Can someme pls confirm if there is any syntax change is required?

cfValues['Issue sub-type'] == 'Enhancement' || cfValues['Issue sub-type'] == 'Defect' || cfValues['Issue sub-type'] == 'Role Change' || cfValues['Issue sub-type'] == 'New Development' || cfValues['Issue sub-type'] == 'Configuration Change'

2 answers

1 accepted

1 vote
Answer accepted
Henning Tietgens
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.
August 5, 2013

If the custom field is a select field you will now get an Option object instead of a string. Try cfValues['Issue sub-type'].getValue() instead of cfValues['Issue sub-type']

mehala n
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.
August 5, 2013

Thanks Much Henning.It works now

mehala n
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.
August 5, 2013

Can you pls tell if there is any change required in the below script?

def e = customFieldManager.getCustomFieldObjectByName('Level of Effort')
def i = customFieldManager.getCustomFieldObjectByName('Impact on functionality')
issue.getCustomFieldValue(e) != null && issue.getCustomFieldValue(i) != null

I have this scripted validator for "Generate Checklist" transition.Getting [InvalidInputException: [Error map: [{}]] [Error list: [[The Level of Effort and Impact on functionality fields must be completed prior to generating the checklist.]]]

This was working good in 4.2 ,Could you please help?

Thanks

Henning Tietgens
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.
August 5, 2013

Looks good for me.

mehala n
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.
August 7, 2013

Hi

My scripted validtaor gets failed (Message given in
Error Message field is getting diaplyed)when I issue the code as below

def e = customFieldManager.getCustomFieldObjectByName('Level of Effort')
def i = customFieldManager.getCustomFieldObjectByName('Impact on functionality')
issue.getCustomFieldValue(e) !=null || issue.getCustomFieldValue(i) !=null

Where as it gets thru when I modified the condtion for ==(as below)

def e = customFieldManager.getCustomFieldObjectByName('Level of Effort')
def i = customFieldManager.getCustomFieldObjectByName('Impact on functionality')
issue.getCustomFieldValue(e) ==null || issue.getCustomFieldValue(i) ==null

But My requiremet is !=null should get pass.

So here the problem is def e def i are getting interpretted as null.. can you please help to pass this validator?

Henning Tietgens
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.
August 7, 2013

What's the error message? Are the names of the CFs correct? Try to debug with log.debug "" messages what the values of e and i are.

0 votes
mehala n
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.
August 7, 2013

I got it fixed henning..Actually these fields needs to be set via the JIRA Ticket.Since Iam new to JIRA .. I didnt understand the basics.

thanks much for your reposnse.

mehala n
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.
August 11, 2013

Hi Henning

I get the below error in Script14.groovy.(there is no such groovy in the script path)

2013-08-12 04:14:58,985 http-6443-17 ERROR wb391456 254x2016x17 ugih9r 10.185.5.137,10.185.160.15 /secure/WorkflowUIDispatcher.jspa [onresolve.jira.groovy.GroovyCustomField] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:Script14.groovy: 1: expecting '(', found 'Issue' @ line 1, column 4. if Issue Classification = "System Change" ^ 1 error javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:Script14.groovy: 1: expecting '(', found 'Issue' @ line 1, column 4. if Issue Classification = "System Change" ^ 1 error at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:117) at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:216) at javax.script.ScriptEngine$eval.call(Unknown Source) at com.onresolve.jira.groovy.GroovyCustomField.getValueFromIssue(GroovyCustomField.groovy:150) at com.atlassian.jira.issue.fields.CustomFieldImpl.getValue(CustomFieldImpl.java:384)

Can u pls tell the cause for this kind of error?

Thanks

Henning Tietgens
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.
August 11, 2013

That's an error from the code of a scripted field. There must be a line like

if Issue Classification ...

The condition of an if statement has to be in ().

mehala n
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.
August 12, 2013

Hi Henning,

Below is the Multi Checklist field script Validator.

// set properties default value if missing
def cp = customFieldManager.getCustomFieldObjectByName('Checklist Properties')
def properties = issue.getCustomFieldValue(cp)
properties?.contains("Default checklist items for Overall Impact level")

Here always it gets evaluated to false and I get the error message I defined.

Pls help

Henning Tietgens
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.
August 12, 2013

Please try def properties = issue.getCustomFieldValue(cp)?.value, because it's an Option object for fields with multiple possible values.

The error message must be from another script.... do you have other scripts?

mehala n
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.
August 12, 2013

Still getting the same error(here error I meant is the error defined by me to be thrown when the condition is not satisfied ,But the checkbox of "Default checklist items for Overall Impact level" is checked already in the Checklist description )

// set properties default value if missing
def cp = customFieldManager.getCustomFieldObjectByName('Checklist Properties')
def properties = issue.getCustomFieldValue(cp))?.value
properties?.contains("Default checklist items for Overall Impact level")

I get this error becoz the variable properties is not reading the value as it expects.

Kindly help

mehala n
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.
August 12, 2013

Error at log :

java.lang.ClassCastException: java.lang.String cannot be cast to com.atlassian.jira.issue.customfields.option.Option

Henning Tietgens
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.
August 12, 2013

There is an ")" to much before the question mark in the def properties row.

mehala n
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.
August 13, 2013

Sorry ,that was a typo error.) is not there in my script validator.

// set properties default value if missing
def cp = customFieldManager.getCustomFieldObjectByName('Checklist Properties')
def properties = issue.getCustomFieldValue(cp)?.value
properties?.contains("Default checklist items for Overall Impact level")

Henning Tietgens
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.
August 13, 2013

Please try this and post the log.

// set properties default value if missing
def cp = customFieldManager.getCustomFieldObjectByName('Checklist Properties')
log.error "customFieldManager: $customFieldManager"
log.error "cp: $cp"
def properties = issue.getCustomFieldValue(cp)?.value
log.error "value: ${issue.getCustomFieldValue(cp)}"
log.error "value.class.name: ${issue.getCustomFieldValue(cp)?.class?.name}"
log.error "value.value: ${issue.getCustomFieldValue(cp)?.value}"
log.error "properties: $properties"
log.error "properties.class.name: ${properties?.class?.name}"
properties?.contains("Default checklist items for Overall Impact level")

Suggest an answer

Log in or Sign up to answer