Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How do I add javascript code to a built-in script in ScriptRunner v5.4+

In ScriptRunner v5.3, I added some custom javascript via a script fragment. The js added an event listener to when a particular (custom) canned script was loaded, so that I could wire up change listener to a project select drop-down (which only existed on the DOM after the canned script was loaded). This other listener used a REST call to load issues for the selected project that fit a JQL query. The code is as follows:

!(function ($) {
    "use strict";

    $(function () {
        var scriptName = "com.onresolve.scriptrunner.canned.jira.admin.ReconcileGbhTime";
        $(document).on("/start/" + scriptName, scriptLoad);

        function scriptLoad() {
            var projectSelect = $("select#project");
            var issueSelect = $("select#issue");

            function getIssuesForProject() {
                var params = {
                    jql: "project = '" + projectSelect.val() +  "' AND statusCategory = 'In Progress' "
                        + "AND issuetype in standardIssueTypes() and issuetype != Deliverable",
                    fields: "summary",
                    maxResults: -1 //absolute max is 1000
                };

                $.getJSON("/rest/api/2/search", params, function(res) {
                    issueSelect.empty();
                    issueSelect.append(new Option("", ""));
                    for(let issue of res.issues) {
                        issueSelect.append(new Option(issue.key + ": " + issue.fields.summary, issue.key));
                    }
                    issueSelect.change();
                });
            }

            projectSelect.change(getIssuesForProject);
            getIssuesForProject();
        }
    });
})(AJS.$);

In ScriptRunner v5.4, it appears the admin section has been changed quite a bit, and no “/start/<script-name>” event is getting fired when I select a built-in script. Therefore, the project drop-down has no change listener and the issue drop-down is never populated.

What event can I listen to, other how can I otherwise add an event to the drop-down that is created as part of this canned script?

p.s. I already figure out that the JQuery selector for the drop downs needs to be replaced with something like:

$("label[for='project']").siblings("select");

1 answer

Hi,

I have a similar issue on my side, but instead of using Web Fragment to include JavaScript, I was adding a script tag in the description of a built-in script. This script was executed with version 7.5.3 of JIRA and SR 5.2.1, but it is not executed anymore with SR version 5.4.49.

alert("load");

JIRA.HideBuiltIns = JIRA.HideBuiltIns || (function() {
return {
init: function() {
alert("do something");
}
};
})();

AJS.$(document).ready(function() {
alert("onready");
setTimeout(JIRA.HideBuiltIns.init, 10);

// Button Back to List also needs to hide built-ins
AJS.$("#cancel").click(function() {
alert("oncancel");
JIRA.HideBuiltIns.init();
})
});

Thanks

Can we customise eazyBi report using JavaScript in Jira Script Runner ? 

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you