4

I've written some Javascript for a JIRA instance that automatically fills a field when creating an issue. It works just as expected if I open the 'Create Issue' screen in a new window. However, when 'Create Issue' appears in a dialog box, my script doesn't run. How would I enable my script to run when the 'Create Issue' dialog screen opens in a window? Below is my code:

/*
 * Automatically fills the summary field of an issue and hides the field at issue creation.
*/

jQuery(document).ready(function($) {

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
    autoFillSummary();
});

autoFillSummary();

// Automatically fill the summary field with a default value.
function autoFillSummary(){
    var issueType = $('#issue-create-issue-type').text();
    var reporter = $('#reporter').val();
    var d = new Date();
    d = d.toDateString();
    var summaryVal = reporter + " - " + "[ " + d + " ]";
    if(issueType === "Job"){
        $('#summary').val(summaryVal);
        $('#summary').closest('div.field-group').hide();
        $('#reporter').closest('div.field-group').hide();
    }
}  

});

The id for the dialog is create-issue-dialog Thank you in advance for any help you can provide me.

3 Answers 3

3

i would do it this way:

jQuery(document).ready(function($) {

  $('#create-issue-dialog').dialog({
    autoOpen: false,
    open: function(event, ui) {
      JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e, context) {
        autoFillSummary();
      });
    }
  });

  // Automatically fill the summary field with a default value.
  function autoFillSummary() {
    var issueType = $('#issue-create-issue-type').text();
    var reporter = $('#reporter').val();
    var d = new Date();
    d = d.toDateString();
    var summaryVal = reporter + " - " + "[ " + d + " ]";
    if (issueType === "Job") {
      $('#summary').val(summaryVal);
      $('#summary').closest('div.field-group').hide();
      $('#reporter').closest('div.field-group').hide();
    }
  }
});

I have not used JIRA ever.

Sign up to request clarification or add additional context in comments.

1 Comment

This doesn't seem to be the solution but thanks for the help and the quick response.
1
AJS.toInit(function () {
    autoFillSummary();
});

JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
    autoFillSummary();
});

// Automatically fill the summary field with a default value.
function autoFillSummary(){
    var issueType = $('#issue-create-issue-type').text();
    var reporter = $('#reporter').val();
    var d = new Date();
    d = d.toDateString();
    var summaryVal = reporter + " - " + "[ " + d + " ]";
    if(issueType === "Job"){
        $('#summary').val(summaryVal);
        $('#summary').closest('div.field-group').hide();
        $('#reporter').closest('div.field-group').hide();
    }
}  

Try to add AJS.toInit(function () { ... }); it runs your script in create issue form

Comments

0

I have not yet been able to find an ideal solution but as a work-around, I have been able to disable the dialog from appearing and forcing the screen to load into a new page:

/*
 * Automatically fills the summary field of an issue and hides the field at issue creation.
 */

jQuery(document).ready(function($) {

// Disable pop-up window - Forces 'Create Issue' to load in new page.
AJS.$("#create_link").removeClass("create-issue");

autoFillSummary();

// Automatically fill the summary field with a default value.
function autoFillSummary(){
    var issueType = AJS.$('#issue-create-issue-type').text();
    var reporter = AJS.$('#reporter').val();
    var d = new Date();
    d = d.toDateString();
    var summaryVal = reporter + " - " + "[ " + d + " ]";
    if(issueType === "Job"){
        AJS.$('#summary').val(summaryVal);
        AJS.$('#summary').closest('div.field-group').hide();
        AJS.$('#reporter').closest('div.field-group').hide();
    }
}  
});

If anyone figures out a way to avoid disabling the dialog it would be much appreciated.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.