JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context, reason) {
getProjectId();
AJS.$("#jira-button-link").click(function (eve) {
getFunction();
});
});
above function
While going through projects navigation and clicking on that button(the button will appear on the issue) the function calls infinite times
While going through issues navigation and clicking on that button(the button will appear on the issue) the function calls only one time.
i want to call one time only
Is this code you are injecting, or reading from a console?
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.
There is one simple solution - stop trying to inject code into Jira Cloud. It's not supported, it breaks things, usually doesn't work as intended and even if you get it right, it's probably going to break in a few weeks when your system gets upgraded.
I would very strongly recommend looking for an app that can do what you need instead of injecting hard-to-write/maintain code!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context, reason) {
getProjectId();
AJS.$("#jira-button-link").click(function (eve) {
getFunction();
});
});
// Current Issue of the ProjectId
function getProjectId()
{
var return_val="notExist";
AJS.$.ajax
({
url: ((baseUrl==='http://localhost:2990')?(baseUrl+'/jira'):(baseUrl)) +'/rest/api/2/issue/'+ encodeURI(JIRA.Issue.getIssueKey()),
type: "GET",
timeout: 0,
dataType: 'json',
processData: false,
headers: {
"Content-Type": "application/json; charset=utf-8"
},
success: function (response) {
var pId= JSON.stringify(response.fields.project.id).replace(/['"]+/g, '');
$.ajax({
url : contextPath + "/rest/jira-adminpage/1.0/config", //Getting Project and ProjectTemplate list.
type : 'GET', // type of the HTTP request
success : function(data) {
console.log(JSON.stringify("Template "+data.projectTemplate));
var obj =jQuery.parseJSON(JSON.stringify(data));
for(var i = 0; i < obj.length; i++) {
var cpListItem =obj[i]['project'];
console.log(cpListItem);
var pTemplateId=obj[i].projectTemplate;
if(cpListItem===pId && return_val==="notExist"){
global_config_project_template_id=pTemplateId;
return_val="Exist";
}
}
if(return_val==="notExist"){
AJS.$("#jira-button-link").hide();
} else {
AJS.$("#jira-button-link").show();
}
}
});
},
error: function (response)
{
console.log(response);
}
});
}
//Get the response from Get issue Details JIRA REST API
function getFunction()
{
AJS.$.ajax
({
url: ((baseUrl=='http://localhost:2990')?(baseUrl+'/jira'):(baseUrl)) +'/rest/api/2/issue/'+ encodeURI(JIRA.Issue.getIssueKey()),
type: "GET",
timeout: 0,
dataType: 'json',
processData: false,
headers: {
"Content-Type": "application/json; charset=utf-8"
},
success: function (response)
{
console.log("response" +response.key);
console.log(JSON.stringify(response.id));
// console.log(JSON.stringify(response.fields.assignee.key));
if(response.fields.assignee == null){
alert("Jira project can't be created. Please assign the issue to an active Jira user!");
}
else{
// if (!hasProject(response.key.toString())) {
//------ This hasProject function is handled by itself in the create project function ---------//
createProject(response.key.toString(), response.fields.summary, response.fields.assignee.name,((baseUrl == 'http://localhost:2990') ? (baseUrl + '/jira') : (baseUrl)) + '/browse/' + encodeURI(JIRA.Issue.getIssueKey()));
// }
}
console.log(((baseUrl=='http://localhost:2990')?(baseUrl+'/jira'):(baseUrl)) +'/browse/'+encodeURI(JIRA.Issue.getIssueKey()));
},
error: function (response)
{
console.log(response);
}
});
}
//------ This hasProject function is handled by itself in the create project function ---------//
//This Project checks whether the project already exist using GET -Project details JIRA REST API
// function hasProject(keyValue) {
//
// keyValue = keyValue.replace("-", "");
//
// AJS.$.ajax
// ({
//
// url: ((baseUrl=='http://localhost:2990')?(baseUrl+'/jira'):(baseUrl)) +'/rest/api/2/project/' + encodeURI(keyValue) ,
// type: "GET",
// timeout: 0,
// dataType: 'json',
// processData: false,
// headers: {
// "Content-Type": "application/json; charset=utf-8"
// },
//
// success: function (response) {
// console.log(JSON.stringify(response));
// alert("Jira project can't be created. Project already exists!");
// return true;
// },
//
// error: function (response) {
// console.log(response);
// // alert("Jira project has error in creating ");
// return false;
//
// }
// });
// }
//This function Post the response Of the Issue Details Using Create Project Shared Template JIRA REST API
function createProject(keyValue,summary,lead,issueUrl)
{
var originalKeyValue = keyValue;
keyValue = keyValue.replace("-","");
console.log(keyValue);
summary = summary.trim();
console.log(summary);
AJS.$.ajax
({
url: urlToAPI[baseUrl],
type: "POST",
timeout: 0,
dataType: 'json',
processData: false,
headers: {
"Content-Type": "application/json; charset=utf-8",
// "Authorization": "Basic BQIY-ECXG-89S1-0YY4_c7fa881c235424b1b130999f1ddb726af2ec9a42_lin="
// "Authorization" : "Basic " + btoa(lead + ":" + "")
},
data: JSON.stringify({
"key": keyValue,
"name": originalKeyValue+" "+summary,
"lead": lead,
"url": issueUrl,
"projectTypeKey": "business",
"templateProjectId":global_config_project_template_id
//"templateProjectId":"13303"
}),
success: function (response) {
console.log(JSON.stringify(response));
console.log("keyValue"+response.key);
alert("Jira project has been created. Now you will be navigated to the project summary screen.");
window.location.replace(((baseUrl=='http://localhost:2990')?(baseUrl+'/jira'):(baseUrl)) +'/projects/'+ keyValue +'/summary');
},
error: function(xhr, status, error) {
console.log(xhr);
var errorMsg = eval("(" + xhr.responseText + ")");
var err=JSON.parse(errorMsg.message);
console.log(errorMsg);
if(err.errorMessages.length > 0)
alert("Jira Project not created. Error Cause: "+JSON.stringify(err.errorMessages[0]));
else{
errorString="";
Object.keys(err.errors).forEach(function(item,index){
errorString+=(index+1)+". "+err.errors[item]+"\n";
});
alert("Jira Project not created. Error Cause: \n"+errorString);
}
}
});
}
For above while calling through the project navigation in inspect getting like get function is calling repeatedely
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.