Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root


1 badge earned


Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!


Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.


Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!


Scriptrunner dialog submission through javascript


I'm having a problem submitting a form through a scriptrunner custom dialog. A web item is used to open the dialog, where input is collected and the form data is posted to a rest endpoint. Looking at Adaptavist's suggestions and the suggestions here, it sounded like I need to use javascript to post the data from the dialog, so I created a web resource bound to atl.general that looks as follows (with console debug and alert calls):

(function ($) {
$(function () {
AJS.dialog2.on("show", function (e) {
var targetId =;
console.log("In Dialog show, target id: " + targetId);
if (targetId === "sr-dialog") {
console.log("In if statement");
var someDialog = AJS.dialog2(;
$("#submit-button").click(function (button) {
type: "POST",
url: AJS.contextPath() + "/rest/scriptrunner/latest/custom/copytojira",
data: AJS.$(window.opener.document).find("#my-custom-sr-dialog-form").serialize(),
beforeSend: function (request) {
console.log("Ready for POST, before send");
request.setRequestHeader("X-Atlassian-token", "no-check");
success: function(result) { //we got the response
console.log("POST sent");
alert('Successfully called');
return false;
error: function(jqxhr, status, exception) {
alert('Exception:', exception);
}).done(function(response) {
//do whatever needs done in the UI here

All id's match what's in the dialog code (below,) including the submit button and dialog id. I see the function registered, but it's never called when the submit button is pressed. In fact, nothing was happening when the Confirm button is used and I had to add JS in the dialog code to get it to submit the form. The problem is, it still doesn't make the ajax call. No debug statements below the if (targetId === "sr-dialog")  statement are ever reached.

My experience in JS of this type (jquery/ajax) is pretty limited, so I'm hoping someone can offer ideas on why the JS isn't properly associated to the button and called when it's clicked. I also tried calling the rest function directly in the form action, but that was erring on cross domain issues.

Note also that the resulting code places the submit button for the form outside of /form closure. That does seem to be part of the problem. That's why I needed to add more JS to get a submit when pressed. Until adding that, clicking Confirm did nothing.

import groovy.transform.BaseScript
import com.atlassian.jira.component.ComponentAccessor
def baseUrl = ComponentAccessor.getApplicationProperties().getString(APKeys.JIRA_BASEURL)
@BaseScript CustomEndpointDelegate delegate

showCopyDialog { MultivaluedMap queryParams ->

def issueKey = queryParams.getFirst("issueKey") as String;
// get a reference to the current page...
// def page = getPage(queryParams)

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">Copy issue to Jira X</h2>
<a class="aui-dialog2-header-close">
<span class="aui-icon aui-icon-small aui-iconfont-close-dialog">Close</span>
<div class="aui-dialog2-content">
<div id="container" style="width:px">
<form id="my-custom-sr-dialog-form" class="aui" action="#">
<p>Select the project:</p>
<input id="issueKey" type="hidden" value="${issueKey}"
<div class="aui-dropdown2-section">
<select id="projectKey">
<option value="Proj1">Proj 1</option>
<option value="Proj2">Proj 2 </option>
<button id="submit-button" name="submit-button" class="aui-button aui-button-primary">Confirm</button>
<footer class="aui-dialog2-footer">
<div class="aui-dialog2-footer-hint">Select the project, click copy to copy issue. </div>


The JS snippet added to the above:

 <script type="text/javascript">

$(document).ready(function() {
$("#submit-button").click(function() {


1 answer

Suggest an answer

Log in or Sign up to answer

What works for me is to include the form handling script inside the dialog string in the REST endpoint, instead of adding it as a resource. Before your form code, add the handling JS in <script> tags.


Also in the script block, for POST, try XMLHttpRequest

var xhttp = new XMLHttpRequest();"POST", "${baseUrl}/rest/scriptrunner/latest/custom/restendpoint", false);                    

xhttp.setRequestHeader("Content-type", "application/json");                    

AUG Leaders

Atlassian Community Events