Adding javascript to hide and prefil summary while creating an issue

Henning Tietgens
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 24, 2014

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Trevor Hunt
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 24, 2014

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.

Henning Tietgens
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 27, 2014

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

mika nokka October 4, 2016

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

Mika

TAGS
AUG Leaders

Atlassian Community Events