• Community
  • Products
  • Marketplace Apps
  • Questions
  • 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

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

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

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

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

I tried this and it work fine.

Thanks Kristian!

Glad I was able to help.

Kristian

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

357 views 0 6
Read article

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