Adding javascript to hide and prefil summary while creating an issue

I want to hide the summary field while creating an issue (and prefill it depending on the content of two customfields) in JIRA 6.0.8 (or higher).

I tried a lot of solutions found here in answers but no solutions works in every situation. My tests are the following, I want to hide the summary in project A and issuetype a:

1. Click on Create Issue while an issue (A/a) is displayed

2. Click on Create Issue while an issue (A/x) is displayed, change to A/a

3. Click on Create Issue while an admin page is displayed (or CTRL click) to open a new page, select A/a and click Next

The solution works for 1. and 3. but not for 2.

This is my current solution:

I created a (number) custom field "NoSummaryField" and added the folowing code to the description of the field

<script type="text/javascript">
AJS.$(document).ready(function () {
    function noSummaryField() {
        if (AJS.$("label:contains('NoSummaryField')").length > 0) {
            AJS.$("label:contains('NoSummaryField')").parent().hide();
            AJS.$("input#summary").parent().hide();

            AJS.$("#create-issue-submit").click(function(){
                if (AJS.$("label:contains('NoSummaryField')").length > 0) {
                    AJS.$("input#summary").val(".");
                };
            });
        };
    };
    noSummaryField();
};
AJS.$(document).bind('dialogContentReady', function(event, dialog) {
    function noSummaryField() {
        if (AJS.$("label:contains('NoSummaryField')").length > 0) {
            AJS.$("label:contains('NoSummaryField')").parent().hide();
            AJS.$("input#summary").parent().hide();

            AJS.$("#create-issue-submit").click(function(){
                if (AJS.$("label:contains('NoSummaryField')").length > 0) {
                    AJS.$("input#summary").val(".");
                };
            });
        };
    };
    noSummaryField();
});
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e,context) {
    function noSummaryField() {
        if (AJS.$("label:contains('NoSummaryField')").length > 0) {
            AJS.$("label:contains('NoSummaryField')").parent().hide();
            AJS.$("input#summary").parent().hide();

            AJS.$("#create-issue-submit").click(function(){
                if (AJS.$("label:contains('NoSummaryField')").length > 0) {
                    AJS.$("input#summary").val(".");
                };
            });
        };
    };
    noSummaryField();
});
noSummaryField();
</script>

This was my latest attempt. I think repeating the function is not neccessary but who knows?

AJS.$("label:contains('NoSummaryField')").length > 0 tests if the NoSummaryField exists on the current screen, and my tests show that this is working in case 1., 2., and 3. Maybe it's not needed with the script within the description of the field but I tried the script within the announcement banner, too.

Is there a reliable way to execute javascript functions while creating issues, even if the issuetype (or project) is changed on the quick create screen?

Prefilling the summary is not in focus of this question because that's not the problem.

Thanks,

Henning

1 answer

1 accepted

Henning, I've experienced similar frustration(s).

I believe the problem you're running into is related load order... i.e. the field with the script isn't loaded when you initially click the create issue button. One thing you can do is go down the web resource route... adding your script as a web resource.

Another option, I've considered is to create a special field to contain various scripts and nothing more, hide it... and ensure it's on every issue creation screen. It looks like this may be the approach of you've taken.

Am I understanding correctly, that the code above does provide the intended result regardless of which projects you bounce around between?

Either way, I think the webresource approach might solve your problem.

Edit: You'll just need to add paremeters to your script to specify which projects it should take affect on.

Thanks. I thought I could get around building my own plugin :-)

I'm no providing the script as a web-resource at it seems it's working! Currently, this is the script:

function noSummaryField() {
    console.log ("noSummary noSummaryField()")
    if (AJS.$("label:contains('NoSummaryField')").length > 0) {
        AJS.$("label:contains('NoSummaryField')").parent().hide();
        AJS.$("input#summary").parent().hide();

        AJS.$("#create-issue-submit").click(function(){
            if (AJS.$("label:contains('NoSummaryField')").length > 0) {
                AJS.$("input#summary").val(".");
            }
        });
    }
}

AJS.$(document).ready(function(){noSummaryField()});
AJS.$(document).bind('dialogContentReady', function(event, dialog){noSummaryField()});
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e,context){noSummaryField()});
noSummaryField();

There are a lot "noSummary noSummaryField()" messages in the log. Are there some of these bindings which could be skipped for web-resources?

Thanks a lot!

Henning

Thank you for solution! I was able to use it to hide a visible bug in Issue Matrix plugin

Mika

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Friday in Agile

Are you a Jira Service Desk agent? We want to talk to you!

Are you a whiz at handling tickets and looking at how you can further optimize your workflow with automation? Do you tackle detailed customer support questions while simultaneously getting flooded wi...

41 views 0 2
Read article

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