Wednesday, December 28, 2011

Prepopulating JIRA system fields

Sometimes people ask me how to prepopulate JIRA system fields. For example, they want to have some template text appear in the system Description field. The simple JavaScript below does this. Just add it to the Description field's description in the relevant Field Configuration.

<script type="text/javascript">
(function($){
    $(document).ready(function(){
        var projectName = AJS.$("#issue-create-project-name")
        if (projectName != null && projectName.length == 1) {
            var projectName2 = projectName[0].innerText;
            if (projectName2 != null && projectName2 == "MyProject") {
                var templateText = "Sample text goes here\n\nAnd here";
                AJS.$("#issue-create #description")[0].value = templateText
            }
        }
    });
})(AJS.$);
</script>

This example only affects issues that are created in the JIRA project named MyProject. Your template text has to be escaped HTML and I don't think it will like Wiki markup if you're using the Wiki Renderer for your field. Tested with JIRA 4.4.1

1 comment:

  1. With the changes in JIRA 5.x, the description and its JavaScript passenger is no longer displayed everywhere, so prepopulating pop-up issue creation and editing will probably not work,

    ReplyDelete