Hello,
Our organization is relatively new to JIRA (less than 2 years old) and few months back we purchased ScriptRunner to further customize our setup.
We would like to create a "dropdown" field that would pull static values from another "text" field. These fields are used on different screens.
I think we may have to include a filter with the below logic inside a script to load values for the dropdown field.
Custom Field 1 (existing) - Subsystem name (text)
Custom Field 2 (new) - Application (dropdown)
"Application" field available values =
"Subsystem name" field values (CONDITION -> project = "eRA Component Model" AND issuetype = Subsystem AND isactive = Yes)
How do I implement this? Please advice.
Thanks,
Venkat
Hi Venkat
You can get the project through the getIssueContext(), for example
def selectedProjectKey = getIssueContext().getProjectObject().getKey() // or for the name def selectedProjectName = getIssueContext().getProjectObject().getName()
regards, Thanos
Thanks a lot, Thanos. That worked. However, I couldnt get the behaviour to work on "Project" field change, I had to use another field, like "Issue Type", then the above script would work as desired.
BTW, the above solution is to make a text field a select field with JQL output that list ISsues from another project. Is there a way to list values of a particular field and only that field (no Issue key) as values of the select field? Does it have to be like a embedded SQL of some sort?
Thanks for your assistance.
Venkat.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh yes sorry forgot to mention that it should have been an initialiser script. For the second part of your question could you please give an example ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No problem. Thanks.
For the second part of the question, from my above example, is it possible to not show the Issue key, but only display the summary field values?
Please see the attached image.
In the image, I dont want to see "ECM-2" in the dropdown.
Thanks.selectlistconversions.jpg
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Venkat,
One way would be to create your own rest endpoint for it, and then call this one in your conversionList. Very similar to the documentation example Pick Issue from remote JIRA and having something like
response.sections.each { section -> section.issues.each { it.remove("summary") it.remove("summaryText") } }
Let me try to see if there is a way via an ajaxOption (I have to check the src code)
regards, Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Thanos. Let me take a look at your suggestions and get back to you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Thanos,
I tried the example you pointed me to and it doesn seem to pull any Issues (see the attachment). Can you please tell me what's missing?
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import groovyx.net.http.ContentType
import groovyx.net.http.HTTPBuilder
import groovyx.net.http.Method
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
pickRemoteIssue() { MultivaluedMap queryParams ->
//def query = queryParams.getFirst("query") as String
def jqlQuery = "project = RCDC"
def httpBuilder = new HTTPBuilder("http://xxx.xxx.xxx.xx:8080")
def response = httpBuilder.request(Method.GET, ContentType.JSON) {
uri.path = "/rest/api/2/issue/picker"
uri.query = [currentJQL: jqlQuery]
response.failure = { resp, reader ->
log.warn("Failed to query JIRA API: " + reader.errorMessages)
return
}
}
response.sections.each { section ->
section.issues.each {
// delete the image tag, because the issue picker is hard-coded
// to prepend the current instance base URL.
it.remove("img")
}
}
return Response.ok(new JsonBuilder(response).toString()).build()
}
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.
Thanks Thanos.
I was able to use the sample - https://scriptrunner.adaptavist.com/latest/jira/behaviours-conversions.html#_walkthrough_pick_from_jira_issues to setup a initilizer script to load JIRA Issues from another project into a text field as a select list.
However, I need to auto-select the value from the dropdown based on the out-of-box project selection.
I am now using the below script on the "Project" field change behaviour. Can you please assist in the highlighted areas?
def selectedProject = getFieldById(getFieldChanged()).getValue()
def jqlSearchField = getFieldByName("Subsystem")
jqlSearchField.convertToSingleSelect([
ajaxOptions: [
url : getBaseUrl() + "/rest/scriptrunner-jira/latest/issue/picker",
query : true,
data : [
currentJql : "project = 'eRA Component Model' AND Summary ~ ${selectedProject} ORDER BY key ASC",
],
formatResponse: "issue"
],
css : "max-width: 500px; width: 500px",
])
I have trouble using "Project" field in behaviours.
Thanks a lot in advance.
Venkat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Venkat Krishnamoorthy and @Thanos Batagiannis [Adaptavist] ,
I have a similar requirement. I need to create a custom select list with dynamic options and I tried the script mentioned here:
Here, options are displayed as : Issue type icon<space>Issue Id<space>Summary
But I need to display: ValueOfACustomField<space>Summary
Kindly let me know, how can I achieve the same. Any help would be appreciated
Thanks and Regards,
Swapnil Srivastav.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Venkat,
I think you mean something like Select List Conversions ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.