Hello,
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 getFieldById("customfield_12003").convertToSingleSelect([ 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.
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.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.