Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 21:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hi everyone,
it is possible to clone an issue to one or more projects based on a projectlist?
here is an example:
an issue needs to be cloned to four jira projects. i want to execute a transition called for example "clone issue to projects". then a list comes up in which i need to define to which projects this issue needs to be cloned.
best
toni
Rest Endpoint
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import com.atlassian.jira.component.ComponentAccessor
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import groovy.json.JsonSlurper
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
getProjects(httpMethod: "GET", groups: ["jira-software-users"]) { MultivaluedMap queryParams, String body ->
def query = queryParams.getFirst("query") as String
def prList = ComponentAccessor.getProjectManager().getProjectObjects()
def filtertList = prList.findAll { project -> project.getName().toLowerCase().contains(query.toLowerCase()) }
def rt = [
items : filtertList.collect { project ->
[
value: project.getName(),
html : project.getName(),
label: project.getName(),
displayName: project.getName(),
]
},
total : filtertList.size(),
footer: "Wähle das Projekt aus ...",
]
return Response.ok(new JsonBuilder(rt).toString()).build()
}
behaviour
def searchField = getFieldByName("Projekt")
searchField.convertToMultiSelect([
ajaxOptions: [
url : "BASEURL/rest/scriptrunner/latest/custom/getProjects",
query: true, // keep going back to the sever for each keystroke
minQueryLength: 1,
keyInputPeriod: 500,
formatResponse: "general",
]
]
)
Hello @Antonio D_Errico
Great to see the complete code sample, if you think my answer helped you in your requirement please upvote/accept. thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Antonio D_Errico
Yes this is possible. When you click on a transition then you can have a transition screen and in that transition screen you can have a variable which is a "project picker" custom field.
Base don the values selected in the project picker custom field you can select the projects in which to clone the issues in the post-function of the transition. And once the cloning is done then you can clear the custom field for next time.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also, since Jira doesn't support multi-select project picker. Thus, you can create a custom field like the ones here which displays dynamically the actual list of projects
https://scriptrunner.adaptavist.com/latest/jira/behaviours-conversions.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i dont find the example for a mutliselect field for projects only for issues
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The example of issues is there, you can create a similar example for projects using REST API call which you also described. Basically use REST API to fetch project list and then let user mult-select options from the list.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi @Tarun Sapra
i am not familiar with the rest api and the groovy. so i am a little bit lost at this moment.
i understand that i need a rest endpoint but i am not able to build it up.
how should the rest endpoint look like:
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.json.JsonBuilder
import groovy.transform.BaseScript
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
doSomething(
httpMethod: "GET", groups: ["jira-administrators"]
) { MultivaluedMap queryParams, String body ->
return Response.ok(new JsonBuilder([abc: 42]).toString()).build()
}
best regards
toni
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Antonio D_Errico
I am not talking about created a custom REST endpoint but calling the REST API of JIRA
In the above example they are calling REST API of confluence but you can call REST API of JIRA which returns the project list.
https://docs.atlassian.com/software/jira/docs/api/REST/7.6.1/#api/2/project-getAllProjects
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi @Tarun Sapra
ok thank you.
the initilaiser looks like this but the field says no matches.
getFieldByName("Projekt").convertToMultiSelect([
ajaxOptions: [
url : getBaseUrl() + "/rest/api/2/project",
query: true,
formatResponse: "general"
]
])
If i open the api call over my brower i get the json output.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the call you have to parse JSON and then it will work.
LIke in one of the examples in the link i shared they are parsing the response so you have to parse the response as well.
def response = httpBuilder.request(Method.GET, ContentType.JSON) {
uri.path = "/rest/api/2/issue/picker"
uri.query = [currentJQL: jqlQuery, query: query, showSubTasks: true, showSubTaskParent: true]
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.
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.