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.$);
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.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.