Behavior Plugin - Setting value of a Select custom field based on value selected in other Select custom field not working, even though the log shows everything working fine

Bharat Kavade January 27, 2016

Hello,

I am trying to set a value of Select field (Product Version) based on value user selects in another Select field (Project Code) on issue creation screen. 

JIRA Version: 5.0.1

Behavior Plugin Version: 0.5.0

I have below a behavior added and linked to a project I am using (Test_Project). Also, this behavior is added for "Project Code" custom field.

 

import org.ofbiz.core.entity.GenericValue
import com.atlassian.core.ofbiz.util.OFBizPropertyUtils

def ProjectCodeField = getFieldById("customfield_11304")
def ProductVersionField = getFieldById("customfield_11302")

if ( ProjectCodeField.getValue() == "ProjCode1" ) {
ProductVersionField.setFormValue ("ProdVer1")
}
else if ( ProjectCodeField.getValue() == "ProjCode2" ) {
ProductVersionField.setFormValue ("ProdVer2")
}
else {
ProductVersionField.setFormValue ("Other")
}

 

where customfield_11304 = Project Code and customfield_11302 = Product Version.

Options in Project Code Select list --> ProjCode1ProjCode2

Options in Product Version Select list --> ProdVer1, ProdVer2, Other

I have logging on and can see below see below sentence in the log file. From the sentence it looks like the operation is going fine, but still the value of "Product Version" field does not change on the create screen and stays none.


2016-01-27 20:17:19,229 http-8080-57 DEBUG jiraadmin 1217x17573x1 1c82ojy 192.195.172.102 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.groovy.BehaviourManagerImpl] Returning map: [customfield_11302:[setValue:ProdVer2, fieldType:com.atlassian.jira.plugin.system.customfieldtypes:select, displayName:Product Version]]


2016-01-27 20:17:22,744 http-8080-57 DEBUG jiraadmin 1217x17574x1 1c82ojy 192.195.172.102 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.groovy.BehaviourManagerImpl] Returning map: [customfield_11302:[setValue:ProdVer1, fieldType:com.atlassian.jira.plugin.system.customfieldtypes:select, displayName:Product Version]]


I'll appreciate the help!

3 answers

1 accepted

2 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 29, 2016

Hi Bharat,


When setting a select list field inside Behaviours you need to specify the ID option of the option to set and not the value.  In your example above that should be the ID for the ProdVer1 or ProdVer2 options.

Below I enlcose a sample behaviours script which shows how you can set a select list field called Request Type based on a select list field called Client.

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

// Get a pointer to my select list fields
def clinetSelectList = getFieldByName("Client")
def requestTypeSelectList = getFieldByName("Request Type")

// Get the Value of the Client Field
def clientVal = clinetSelectList.getValue()

// If the XX option is selected then set the Request Type Field to Option A
if(clientVal == "XX"){
// Set the value of the field using the option ID for the A value
    requestTypeSelectList.setFormValue(10400) 
}

 

I hope this helps.

Kristian

0 votes
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 11, 2016

Glad I was able to help.

Kristian

0 votes
Bharat Kavade February 11, 2016

Sorry for late response. Was busy in some other priority work.

I tried this and it work fine.

Thanks Kristian!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events