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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,553,430
Community Members
 
Community Events
184
Community Groups

Show Scripted Field on Transition Screen

I have a scripted field for which I need to display on a transition screen. The code will generate a <select> drop down based on another custom field value in the ticket. I am having trouble getting this field to appear on the transition screen.

 

I have followed this article with no success: https://scriptrunner.adaptavist.com/5.0.4/jira/scripted-fields.html#_displaying_script_fields_in_transition_screens

I know my code is working because the preview of the code is working just fine and displaying how I expect.

 


...

/*Redacted classes for brevity*/

def CreateOption(String OptionVersion, String OptionId) {
    return "<option value=\"${OptionId}\">${OptionVersion}</option>"
}

def CreateSelect(ops) {
    def temp = []
    ops.each {o -> temp.push(CreateOption(o.Version.toString()))}
    return "<select>${temp}</select>"
}

def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_13154")
def cFieldValue = issue.getCustomFieldValue(cField)

OctopusAction o = new OctopusAction(OctopusServer);
def projName =  o.getProjectByName(cFieldValue.toString()).Id;
def releases = o.getAllReleases(projName).Items

def options = []
releases.each{r->
    options.push(CreateOption(r.Version.toString(), r.Id.toString()))
}
return "<select>${options}</select>"

 

3 answers

0 votes
Scott Boisvert
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Dec 03, 2020

I know this is two years old, but is there a solution to this. My scripted field works fine on the view screen, but adding the javascript recommended by Adapatvist/ScriptRunner Scripted Fields just displays the script on the screen under the field I place it in.

Joanna Choules
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.
Jan 06, 2021

Hi Scott,

Can you describe exactly where you're adding the JS?

Scott Boisvert
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 06, 2021

@Joanna Choules The script goes in the description of another field on the screen. The issue I was having though is that you have to have Allow HTML In Custom Field Descriptions enabled, it was disabled in our environment.

Joanna Choules
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.
Jan 06, 2021

Hi Scott,

Thanks for letting me know. Did enabling that option resolve the issue for you?

Scott Boisvert
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Jan 06, 2021

@Joanna Choules Yep it did.

Hi,

Please add the javascript code and also please confirm the JIRA and SR version? From the ticket I can see the version of JIRA is 7.6.1 and SR 5.2.2.

yes that is correct. Here is the JS

 

<script type="text/javascript">
(function ($) {

    // ---------------------------------- MANDATORY CONFIG ----------------------------------
    var fieldName = "Octopus Release" // display name - does not have to match the name of the field
    var fieldId = "customfield_13154" // field Id
    // ---------------------------------- END MANDATORY CONFIG ------------------------------

    function addCalculatedField(e, context) {
        var $context = $(context);

        // if you want you can limit this to certain actions by checking to see if this value is in a list of action IDs
        if (!$("input[name='action']").val()) {
            return;
        }

        // multiple handlers can be added if you do an action, then cancel repeatedly
        if ($context.find("#scriptedfield_" + fieldId).length > 0) {
            return;
        }

        var issueKey = $("meta[name='ajs-issue-key']").attr("content");
        if (!issueKey) {
            issueKey = $("#key-val").attr("rel"); // transition screens in full page mode
        }

        var paddingTop = AJS.$("meta[name='ajs-build-number']").attr("content") < 6000 ? "1" : "5";

        var fieldGroupHtml = '<div class="field-group">' +
            '<label for="' + fieldId + '">' + fieldName + '</label>' +
            '<div style="padding-top: ' + paddingTop + 'px" id="scriptedfield_' + fieldId + '"> ' +
            '<span class="aui-icon aui-icon-wait">Loading, please wait</span></div>' +
            '</div> ';

        // Modify this select if you want to change the positioning of the displayed field
        $context.find("div.field-group:first").before(fieldGroupHtml);

        $.ajax({
            type: "GET",
            "contentType": "application/json",
            url: AJS.params.baseURL + "/rest/api/2/issue/" + issueKey + "?expand=renderedFields&fields=" + fieldId,
            success: function (data) {
                if ("fields" in data && fieldId in data.fields) {
                    var fieldValue = data.fields[fieldId];
                    $context.find("#scriptedfield_" + fieldId).empty().append(fieldValue);
                }
                else {
                    $context.find("#scriptedfield_" + fieldId).empty().append("ERROR - bad field ID");
                }
            },
            error: function () {
                $context.find("#scriptedfield_" + fieldId).empty().append("ERROR");
            }
        });
    }

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

})(AJS.$);
</script>

So my comment disappeared....Those versions are correct. Here is the JS

 

<script type="text/javascript">
(function ($) {

    // ---------------------------------- MANDATORY CONFIG ----------------------------------
    var fieldName = "Octopus Release" // display name - does not have to match the name of the field
    var fieldId = "customfield_13154" // field Id
    // ---------------------------------- END MANDATORY CONFIG ------------------------------

    function addCalculatedField(e, context) {
        var $context = $(context);

        // if you want you can limit this to certain actions by checking to see if this value is in a list of action IDs
        if (!$("input[name='action']").val()) {
            return;
        }

        // multiple handlers can be added if you do an action, then cancel repeatedly
        if ($context.find("#scriptedfield_" + fieldId).length > 0) {
            return;
        }

        var issueKey = $("meta[name='ajs-issue-key']").attr("content");
        if (!issueKey) {
            issueKey = $("#key-val").attr("rel"); // transition screens in full page mode
        }

        var paddingTop = AJS.$("meta[name='ajs-build-number']").attr("content") < 6000 ? "1" : "5";

        var fieldGroupHtml = '<div class="field-group">' +
            '<label for="' + fieldId + '">' + fieldName + '</label>' +
            '<div style="padding-top: ' + paddingTop + 'px" id="scriptedfield_' + fieldId + '"> ' +
            '<span class="aui-icon aui-icon-wait">Loading, please wait</span></div>' +
            '</div> ';

        // Modify this select if you want to change the positioning of the displayed field
        $context.find("div.field-group:first").before(fieldGroupHtml);

        $.ajax({
            type: "GET",
            "contentType": "application/json",
            url: AJS.params.baseURL + "/rest/api/2/issue/" + issueKey + "?expand=renderedFields&fields=" + fieldId,
            success: function (data) {
                if ("fields" in data && fieldId in data.fields) {
                    var fieldValue = data.fields[fieldId];
                    $context.find("#scriptedfield_" + fieldId).empty().append(fieldValue);
                }
                else {
                    $context.find("#scriptedfield_" + fieldId).empty().append("ERROR - bad field ID");
                }
            },
            error: function () {
                $context.find("#scriptedfield_" + fieldId).empty().append("ERROR");
            }
        });
    }

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

})(AJS.$);
</script>
Joanna Choules
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.
Feb 15, 2018

Hi Derek,

What previewing functionality did you use to check that the code was working? I believe you should only need to add the code to the description of one of the fields that appears on the appropriate screen.

I would just preview by returning a select option. However, if I add the javascript to the description field of the context, nothing shows up. Note there is not a description field of the scripted field. If one exists it is not called description.

Any thoughts here? I am frustrated with this platform.

Hello,

Is there a resolution for this problem? I encountered the same issue...

For more detail, it does not appear that I can even get the blank custom field to show on transition screens. I have pasted the Javascript code in every single 'description' field (citation the article) that I can find as it related to field configurations.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events