Popup Create on top of an issue already being created.

Cynthia Fehr
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 28, 2015

Hi,

I'm using javascript to add a template to the description field for a JIRA issue.

Everything works fine except when you press create when you are already on the issue creation screen.  A popup window appears but my description field is empty.  When I am on other screens and I press create issue and the pop up appears there is no problem.  The description field is populated.

Any ideas on why this might be happening?

 

Here is the code I use:

// Add template text to an old-style non-lightbox issue create screen
function addOldText(area) {
if (AJS.$("#issue-create-submit") == null || AJS.$("#issue-create-submit").length == 0) {
return;
}

var projectName = AJS.$("#issue-create-project-name")
if (projectName != null && projectName.length == 1) {
// innerText is Chrome only
var projectName2 = projectName[0].innerHTML;

var issueType = AJS.$("#issue-create-issue-type")
if (issueType != null && issueType.length == 1) {
var issueType2 = issueType[0].innerHTML;
}

if (projectName2 != null && issueType2 != null) {
addText(area, projectName2, issueType2);
}
}
}

// Add template text to a lightbox issue create screen
function addNewText(area) {
// Only when creating issues
if (AJS.$("#create-issue-submit") != null && AJS.$("#create-issue-submit").length != 0) {
// Find the name of the currently selected project

var projectName = AJS.$('#project-field').val();
var issueType = AJS.$('#issuetype-field').val();
addText(area, projectName, issueType);
}
}

function addText(area, projectName, issueType) {
// Add text to the description in the projectName object. The
// field may have text from a previous choice but overwrite it
// area variable is for logging.
if (projectName != null) {
templateText = "";
if (projectName == "TalentSpace Suite (HGN)" || projectName == "TalentSpace Suite" || projectName == "Careers Website" || projectName == "e360-V6" || projectName == "EPM Db" || projectName == "Foundation" || projectName == "Mobile" || projectName == "HRIS Connect" || projectName =="OAuth Server" || projectName =="Outlook Plugin") {
if (issueType == "Bug") {
// Note that both new line and line continuations are used here
var templateText = "Build number\nSite (If applicable)\nBrowser\nExpected results\nActual result\nSteps to reproduce\n\Any workaround or mitigation.\n";
}

}
console.log(AJS.$("#description").length )
if (AJS.$("#description") != null && AJS.$("#description").length > 0) {
AJS.$("#description")[0].value = templateText
}
}
}

(function($) {
AJS.toInit(function(){
// init on load
addNewText('loading')
addOldText('loading')
})
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {
// init on refresh
addNewText('refreshing')
addOldText('refreshing')
});
})(AJS.$);

2 answers

1 accepted

0 votes
Answer accepted
Cynthia Fehr
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
May 6, 2015

Thanks for the answer Pedro...good guess.  I did eventually figure it out.  It was because description turned out to be an array due to there being two on the screen.  So the script was operating on the description behind the popup screen. 

CGM June 17, 2015

Hi, I have the same problem. Did you manage to get it working?

0 votes
Pedro Cora
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 29, 2015

Cyntia,

This is probably happening because your script is being called on load of the Create Screen and when you call it while already being in the screen the script is not being loaded.

wink

Suggest an answer

Log in or Sign up to answer