Hi folks,
i have created dialog window for my project as described here:
https://scriptrunner.adaptavist.com/latest/jira/fragments/WebItem.html
There are some qlitches in JIRA v6.3.1x with javascript, for example the script handling the dialog window is loading only on some pages.
But with JIRA 7 this is solved, so since our customer is going to upgrade to version 7, there is no bother with this.
So what I am trying to do is:
I have a button in the blue administration stripe as a Script-fragment/Custom webitem defined in Scriptrunner - this opens the dialog.
It calls the REST end point (Show Dialog) which is similar to the one on adaptavist page mentioned above.
I can not figure out how to get current project information in this REST end point and fill the information to the returned html template.
Maybe its easy and i am just overlooking something due to lack of my experience with Scriptrunner and JIRA and maybe its not possible to do so at all.
The dialog creates new project version and I dont have any issue context, we should be able to cal it from anywhere within project administration.
Anyone have some suggestions??
Hey Martin,
It depends on the the context of the web item.
So for example if the context of your web item is the operations-top-bar, as in the example, then and assuming that your rest endpoint is
/rest/scriptrunner/latest/custom/doSomething
then in the script fragment link you can have
/rest/scriptrunner/latest/custom/doSomething?issueId=${issue.id}
and then in your rest endpoint you can retrieve the project.
Something like
import com.atlassian.jira.component.ComponentAccessor
import com.onresolve.scriptrunner.runner.rest.common.CustomEndpointDelegate
import groovy.transform.BaseScript
import javax.ws.rs.core.MediaType
import javax.ws.rs.core.MultivaluedMap
import javax.ws.rs.core.Response
@BaseScript CustomEndpointDelegate delegate
doSomething() { MultivaluedMap queryParams ->
def issueId = queryParams.getFirst("issueId") as Long
def project = getProjectFromIssueId(issueId)
log.debug "Project key is ${project.key}"
def dialog =
"""<section role="dialog" id="sr-dialog" class="aui-layer aui-dialog2 aui-dialog2-medium" aria-hidden="true" data-aui-remove-on-hide="true">
<header class="aui-dialog2-header">
<h2 class="aui-dialog2-header-main">Some dialog</h2>
<a class="aui-dialog2-header-close">
<span class="aui-icon aui-icon-small aui-iconfont-close-dialog">Close</span>
</a>
</header>
<div class="aui-dialog2-content">
<p>This is a dialog...</p>
</div>
<footer class="aui-dialog2-footer">
<div class="aui-dialog2-footer-actions">
<button id="dialog-close-button" class="aui-button aui-button-link">Close</button>
</div>
<div class="aui-dialog2-footer-hint">Some hint here if you like</div>
</footer>
</section>
"""
Response.ok().type(MediaType.TEXT_HTML).entity(dialog.toString()).build()
}
def getProjectFromIssueId (Long issueId) {
def issue = ComponentAccessor.issueManager.getIssueObject(issueId)
// you have the project do something
issue?.projectObject
}
Hope that helps.
Regards,
Thanos
Hey Thanos,
thanks for the reply. Yeah your example is correct, that is what i have here - of course without the issue.id param.
I just assume here now, but if I open JIRA first time, open the project admin part ie: Versions tab and then click the button to open the dialog, there will be no issue context right? Because i did not open any issue yet. so the param issue.id will be null in this case right?
Well i am going to try to fiddle with it, maybe i will find the way :)
thanks again, any ohther ideas are very welcome.
Martin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Of course you can just do something like this, when you define Script fragment calling your showDialog endpoint.
/rest/scriptrunner/latest/custom/showDialog?projectKey=${project.key}
works!!
thanks again
M.
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.