You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
I saw information about converting field and connect it to rest endpoint, but can I setFormValue in behaviors via rest endpoint? It returns only one value like:
{"items":[{"value":3437754,"html":3437754,"label":3437754}]}
Script in behaviors:
I've encountered this.
I normally use formField.convertToSingelSelect([ajaxOptions:[...]])
But I found that I can't also set a value programmatically with that.
So, when i need to set the value dynamically, I use formField.convertToSingelSelect().setFieldOptions(map) instead.
Something like this:
import com.atlassian.jira.component.ComponentAccessor
import groovy.json.JsonParserType
import groovy.json.JsonSlurper
import com.atlassian.sal.api.net.Request
import com.atlassian.sal.api.net.TrustedRequest
import com.atlassian.sal.api.net.TrustedRequestFactory
import groovyx.net.http.URIBuilder
import com.onresolve.scriptrunner.runner.customisers.PluginModule
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
@PluginModule TrustedRequestFactory trustedRequestFactory
def options = [:]
options.put("":"") //this is to have a blank option at the top
def url = "$baseUrl/rest/url"
//create a trusted request to the target url
def request = trustedRequestFactory.createTrustedRequest(Request.MethodType.GET, url) as TrustedRequest
request.addTrustedTokenAuthentication(new URIBuilder(baseUrl).host, currentUser.username)
//prepare the parser
def parser = new JsonSlurper().setType(JsonParserType.INDEX_OVERLAY)
//execute the request
def response = request.execute()
def jsonResp = parser.parseText(response)
jsonResp.items.each {
options.put(it.html, it.html)
}
field.convertToSingleSelect().setFieldOptions(options)
field.setFormValue('someDefaultValue')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.