Hi
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.
Hello,
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() {
setTimeout(myFunction,3000);
});
function myFunction(){
HERE YOUR JS CODE
}
Hope this helps,
Fabio
This is working when I click Create button for first time.
But I require each time I press Create button.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.

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

The above is New Card button on Board.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Use one of this constructs:
AJS.$(document).ready( function() {
AJS.$("#gh-create").click(function() {
alert("on button clicked");
});
});
or
AJS.$(window).load( function() {
AJS.$("#gh-create").click(function() {
alert("on button clicked");
});
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The above mentioned scripts are not working.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok, what about this:
$("#someDivOrSomethingElse").bind("DOMSubtreeModified", function() {
alert("DOM changed");
});
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hm, I am out of ideas...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think "card-create" is not correct. You should use a div which is already there and exists all over the time.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I used page an id present in all Jira pages but not working in the script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
And what about AJS.$("body").bind( .......
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
even the above is not showing any alert.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
})
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Please post a picture / screenshot of the two buttons. So I am sure that we speak about the same issue :-)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
(function($) {
/*
AJS.toInit(function(){
// old function
alert("init");
});
*/
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
//alert("entered into greenhopper");
AJS.$("#newOptions").click(function() {
var tex1=AJS.$("#newField_customfield_12051");
//alert(tex1);
if(tex1 == null || tex1 == ''){
alert("Inside 1");
}
else {
//alert("In 2");
var loopvar = 0;
do {
loopvar = setTimeout(temp, 1000);
//alert(loopvar);
//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}");
//alert(flag1);
if(flag1 != null) {
//alert(flag1);
cnt = cnt + 1;
flag = true;
break;
}
}
if(flag == false){
AJS.$(this).remove();
}
});
if(cnt == 0) {
AJS.$("#newField_customfield_12051").parent().hide();
}
}
function grps(){
var groups;
AJS.$.ajax({
url: "/rest/api/2/user?username="+AJS.params.loggedInUser+"&expand=groups",
type: 'get',
dataType: 'json',
async: false,
success: function(data) {
groups = data.groups.items;
}
});
//alert(groups);
return groups;
}
});
})(AJS.$);
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
What do you mean with "new card context"? A new issue? Please post your code, so we can see what you want to do.
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.