Set value of select list conversion based on another select list conversion


I have two text fields (say Address and PhoneNumber) and on both of them, I have setup a select list conversion behavior.  They both query from the same SQL DB table, just one searches for customer records by address and the other by phone number.  Here is the initializer script for one of them:

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours

    ajaxOptions: [
        url: getBaseUrl() + "/rest/scriptrunner/latest/custom/customersbyaddress",
        query: true,
        formatResponse: "general"
    css: "max-width: 500px; width: 500px",

The REST endpoint in both cases returns a list of customer records where the label is just the phone number or address, respectively, the value is a string representation of the entire SQL row, and the HTML is data from the row displayed to the user in a table.

Now, when I select a customer record in the Address field, I also want to automatically set the PhoneNumber field to the phone number of that customer, and vice versa.  I tried to accomplish this using a server-side script, as follows:

import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours

def stringToMap = { String str ->
    return str[1..-2]
        .split(', ')
        .collectEntries { entry ->
            def pair = entry.split(':')
            [(pair.first()): pair.last()]

def phoneField = getFieldById("customfield_11308")
def addressField = getFieldById("customfield_12003")

def value = stringToMap((String)addressField.getValue())

phoneField.setFieldOptions(["value": addressField.getValue(), "label": value.phonenumber, "html": ""])

I also tried phoneField.setFormValue(...), but that doesn't work either.  Also, if there's a better way of doing this, please let me know.

1 answer

On a side note, when I have both behaviors (select list conversion A trying to update B and vice versa), I noticed I can't edit or create issues.  I looked at the browser console and saw the following JS error pop up a few times:

Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
at Class.getDescriptor (batch.js?atlassian.aui.raphael.disabled=true&locale=en-US:1630)
at Class._setDescriptorWithValue (batch.js?atlassian.aui.raphael.disabled=true&locale=en-US:3389)
at HTMLSelectElement.<anonymous> (batch.js?atlassian.aui.raphael.disabled=true&locale=en-US:3389)
at HTMLSelectElement.dispatch (batch.js?atlassian.aui.raphael.disabled=true&locale=en-US:104)
at HTMLSelectElement.h (batch.js?atlassian.aui.raphael.disabled=true&locale=en-US:96)
at Object.trigger (batch.js?atlassian.aui.raphael.disabled=true&locale=en-US:101)
at HTMLSelectElement.<anonymous> (batch.js?atlassian.aui.raphael.disabled=true&locale=en-US:117)
at Function.each (batch.js?atlassian.aui.raphael.disabled=true&locale=en-US:54)
at init.each (batch.js?atlassian.aui.raphael.disabled=true&locale=en-US:47)
at init.trigger (batch.js?atlassian.aui.raphael.disabled=true&locale=en-US:117)

My guess is that the JS error hoses the edit/create form, which prevents the button from submitting.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,213 views 5 10
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