Forums

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

Updating a select list value by changing another select list value

Hemanshu Sood
Contributor
May 24, 2018

Hi All,

I have created a script which allows to update a select list A by changing the value of a select list B. However, it is not working, please suggest:

 

import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript

@BaseScript FieldBehaviours fieldBehaviours


FormField selectList1 = getFieldById("customfield_20650") 
FormField selectList2 = getFieldById("customfield_20156")


def selectList1Val = selectList1.getValue()


if(selectList1Val.toString().contains("Australia")){

selectList2.setFormValue(17305)
}

 

 

error in logs:

 

java.lang.NullPointerException: Cannot get property 'customfield_20650' on null object
at com.onresolve.jira.groovy.user.FormField.getValue(FormField.groovy:181)
at com.onresolve.jira.groovy.user.FormField$getValue.call(Unknown Source)
at Script38.run(Script38.groovy:17)

 

 

What Am i doing wrong here? Please help

1 answer

0 votes
Alexey Matveev
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.
May 24, 2018

Hello,

The problem is that getFieldById("customfield_20650")  returns null. Are you sure that you provide the correct id of the custom field and this custom field is present on the screen?

Hemanshu Sood
Contributor
May 24, 2018

I am using  this script inside the behavior plugin as a serverside script. Also, the field already has a value on the "View" Screen of the ticket and is mapped with the project and ticket type.

Alexey Matveev
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.
May 25, 2018

Behaviours do not work with view screens. They work only with Create, Edit and Transaction screens. What screen do you open when you get the error? Are you sure the field is in that screen?

Hemanshu Sood
Contributor
May 29, 2018

Yes, the field is on the screen.

Thanks Alexey, I think the View screen is the issue here

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events