Script Runner

Venkat Krishnamoorthy November 28, 2016

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

1 vote
Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 10, 2017

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

 

Venkat Krishnamoorthy January 11, 2017

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.

 

Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 11, 2017

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 ?

Venkat Krishnamoorthy January 11, 2017

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

 

Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 11, 2017

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

Venkat Krishnamoorthy January 19, 2017

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

Venkat Krishnamoorthy January 30, 2017

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

 

Venkat Krishnamoorthy February 1, 2017

Forgot the attachment..

0 votes
Venkat Krishnamoorthy January 9, 2017

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

SWAPNIL SRIVASTAV November 11, 2019

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:

https://scriptrunner.adaptavist.com/4.3.3/jira/behaviours-conversions.html#_walkthrough_pick_from_jira_issues 

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.

0 votes
Thanos Batagiannis _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 1, 2016

Hi Venkat,

I think you mean something like Select List Conversions ?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events