Script Runner

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

3 answers

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.

 

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 ?

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

 

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

Thanks Thanos. Let me take a look at your suggestions and get back to you.

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()
}

 

Forgot the attachment..

Hi Venkat,

I think you mean something like Select List Conversions ?

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

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Oct 31, 2018 in Marketplace Apps

Marketplace Spotlight: Zephyr

Hello Atlassian Community! Each month, we run a series of Spotlights to highlight Marketplace vendors and apps that our team thinks this Community would find valuable. In last month's Spotlig...

320 views 0 1
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you