It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Javascript to execute when create button is pressed in Jira agile New card window?


I need to execute some javascript(which restrict some customfield options according to logged-in user) when I press Create button on New Card pop-up of jira agile.

I wrote some javascript but I could not able to execute on jira new card context. Any suggestions.

6 answers


I had the same issue in the past. The problem is that your js code need the complete page load first. I fixed this problem using a timeout :

jQuery(document).ready(function() {

function myFunction(){

Hope this helps,


This is working when I click Create button for first time.

But I require each time I press Create button.

What do you mean with "new card context"? A new issue? Please post your code, so we can see what you want to do.

(function($) {
        // old function
	JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
        //alert("entered into greenhopper");
		AJS.$("#newOptions").click(function() {
			var tex1=AJS.$("#newField_customfield_12051");
			if(tex1 == null || tex1 == ''){
				alert("Inside 1");
			else {
				//alert("In 2");
				var loopvar = 0;
				do {
					loopvar = setTimeout(temp, 1000);
					//alert(typeof loopvar);
				} while (typeof loopvar != 'number');	
		AJS.$("#gh-create").click(function() {
			alert("on buttion clicked");
		function temp() {
			var gps = grps();
			var cnt = 0;
			AJS.$("#newField_customfield_12051 option").each(function(i){
				var flag = false;
				var t1 = AJS.$(this).text();
				for (j = 0; j < gps.length; j++){
					var tem = gps[j].name;
					var conTerm = tem.toString();
					var flag1 = conTerm.match("NDA_" + t1 + "_[a-zA-Z]{2}[0-9]{6}");
					if(flag1 != null) {
						cnt = cnt + 1;
						flag = true;
				if(flag == false){
			if(cnt == 0) {
		function grps(){
			var groups;
				url: "/rest/api/2/user?username="+AJS.params.loggedInUser+"&expand=groups",
				type: 'get',
				dataType: 'json',
				async: false,
				success: function(data) {
					groups = data.groups.items;
			return groups;

This is javascript placed as web-resource module.

when I click New Card button on Board, the script which I wrote is working fine. But when I press Create button on New Card pop-up the alert I placed is not getting executed.

Please post a picture / screenshot of the two buttons. So I am sure that we speak about the same issue :-)

Use one of this constructs:

AJS.$(document).ready( function() {

 AJS.$("#gh-create").click(function() {
            alert("on button clicked");



AJS.$(window).load( function() {

 AJS.$("#gh-create").click(function() {
            alert("on button clicked");


The above mentioned scripts are not working.

Ok, what about this:

$("#someDivOrSomethingElse").bind("DOMSubtreeModified", function() {

    alert("DOM changed");


Hm, I am out of ideas...

I used as

AJS.$("#card-create").bind("DOMSubtreeModified", function() {
	alert("DOM changed");

here card-create is id of div tag of pop-up window.but not working

I think "card-create" is not correct. You should use a div which is already there and exists all over the time.

I used page an id present in all Jira pages but not working in the script.

And what about AJS.$("body").bind( .......

even the above is not showing any alert.

how many tags of "card-create" do you have? More than one? Perhaps you must use

AJS.$("#card-create").each( function(this) {

// bind click event


The above is Create button on New Card pop-up jira-agile.

The above is New Card button on Board.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira Software

[New] Jenkins for Jira Software Cloud and a way to connect your hosted apps

Jenkins is the leading open-source automation server used by startups and enterprise teams to build, test and deploy code to production.   We are excited to announce an official integration betw...

983 views 1 14
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you