Popup Create on top of an issue already being created.

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

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. 

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

0 vote
Pedro Cora Atlassian Team Apr 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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,203 views 13 19
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot