Hello,
I want to create a custom picker scripted field (so your builtin example that calls the country api perfectly fill the need)
BUT I want this list (more like the API call made to the external service) filtered based on the value of a field from the issue creation screen.
The flow is as follows:
I tried using the getFieldByName('project').value function from the behaviour’s but it is not recognized.
Should I need to import a specific library in order to use this function? which one? (it’s not listed in the doc).
Best.
To clarify:
Based on your answer and this community answer https://community.atlassian.com/t5/Marketplace-Apps-Integrations/Re-formField-getValue-Select-List-as-string/qaq-p/1245219/comment-id/62436#M62436
Here is my MNWE (minimal non-working example):
I created from this template: "custom picker".
import com.onresolve.scriptrunner.canned.jira.fields.model.PickerOption
// Imported from the community answer
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
FormField field = getFieldById(getFieldChanged())
// Get the value of the summary in the creation screen
def summary = getFieldById("summary")
// Simulate an API response, which is a list of values
List myList = [
"some default value"
]
// Append the value of the "summary" form field to the list
myList.add(summary.getValue().toString())
log.info(myList)
/*
Search is called when the user opens the drop-down, and when they start typing.
`inputValue` will contain what they type to search through the list. It may be an empty string.
This should return a Collection of "objects", e.g. Version, ApplicationUser - in this case we will return a Map.
*/
search = { String inputValue ->
def result = myList.findAll {it ->
it.toLowerCase().contains(inputValue.toLowerCase())
}
result ?: ["Other (in description)"]
}
/*
`toOption` will be called for each item returned by `search`.
The first parameter will have the type of whatever object we are representing, in this case Map.
You are also passed a Closure that can be used to highlight search matches in the display value.
You must return a com.onresolve.scriptrunner.canned.jira.fields.model.PickerOption, with at least `value` and `label` keys.
The `value` should be a String, and is the unique identifier that is stored in the database.
We will call `getItemFromId` with this ID to convert back to the "object".
The `label` value is used for sorting and uniqueness, and will be displayed if the `html` key is not used.
The `html` value should be used if you want to highlight the matching search term(s) within the result, or include other HTML in the option.
Optionally, you can include an `icon` key which should be the URL to an icon representing this option.
*/
toOption = { String it, Closure<String> highlight ->
new PickerOption(
value: it,
label: it,
// The second argument `false` means to highlight the search term even in the middle of the result.
// Without this, or if this is `true`, only matches at the beginning of words are highlighted.
html: highlight(it, false),
)
}
/*
`getItemFromId` is called to convert from the ID back to the object you are representing, in this case a Map.
If the object no longer exists then you should return null.
*/
getItemFromId = { String it ->
it
}
/*
`renderItemViewHtml` is called to get the view HTML when viewing an issue.
You can use HTML in the value to be displayed, and include other information from the object.
*/
renderItemViewHtml = { String it ->
it
}
/*
`renderTextOnlyValue` is called when doing a CSV export or View -> Printable.
You should not include HTML in output from this closure.
*/
renderItemTextOnlyValue = { String it ->
it
}
There are the results:
The value in the “summary” does not appear in the list below.
Hope it's clearer
To clarify:
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.