Hello,
I need to create the ability to lookup records by phone number from an external database. My current setup is as follows:
1) A REST Endpoint connects to the external database and performs a SQL query given a phone number
2) A select list conversion displays the results to the user as they type a phone number into a text field
My question is how do I get the current text in the text field. For example, if the user types "123-45" into the text field, but has nothing selected, then I want to grab the text "123-45" so I can send it to the REST endpoint to perform the query.
I tried the following code, but it always returns null:
def formField = getFieldById(getFieldChanged()); String phoneNum = formField.getValue();
Community moderators have prevented the ability to post new answers.
I was able to solve the issue by looking at the documentation for behaviors. The current text is stored in a GET parameter called "query" so you can access it through the REST endpoint, as follows:
def query = queryParams.getFirst("query") as String
Awesome... I didn't understand your issue related to the rest endpoint, but yes, that's how to get the params.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No worries, I thought I would need to send the query as a GET param to the REST endpoint myself and was fixated on the behavior as a result. But it turns out that the "query" param is there automatically, and I didn't have to do anything at all!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It's only going to have a value when one of the valid options is set.
Getting the current text should all be done when you configure the select list conversion - that's where you specify the rest endpoint. What's your code for that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jamie,
Here is the code for the initializer function for my behavior:
import com.onresolve.jira.groovy.user.FieldBehaviours import groovy.transform.BaseScript @BaseScript FieldBehaviours fieldBehaviours def formField = getFieldById(getFieldChanged()); String phoneNum = formField.getValue(); getFieldById("customfield_11308").convertToSingleSelect([ ajaxOptions: [ url: getBaseUrl() + "/rest/scriptrunner/latest/custom/customers?phone=$phoneNum", query: true, formatResponse: "general" ], css: "max-width: 500px; width: 500px", ]);
Here is the rest of the configuration:
image2016-11-3 5-24-50.png
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.