How to get the selected value from a custom field select type using Jelly Script?

mary-an ylanan March 3, 2013

Hi,

I want to get the selected value of a select type custom field and assign/set that value to another select type custom field using Jelly Script.

Appreciate any help. Thanks!

2 answers

1 accepted

4 votes
Answer accepted
David Pinn
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.
May 1, 2013

Let's start with the easy part. If you were creating a new issue, you could assign a value to a custom field for that new issue as described in the JIRA Jelly Tag reference documentation.

Since you ask about getting the current value of a custom field, I assume that you want to update an existing issue rather than create a new one. That's not quite so easy because that capability is not provided directly by the JIRA Jelly tags. Instead, you must use some tags in the jelly:core tag library to interact with the JIRA components. The code snippet below shows how you can obtain the value of a custom field called MyField. Hold on tight, because this gets a little hairy.

<!-- Get an instance of ComponentManager -->
<core:invokeStatic className="com.atlassian.jira.ComponentManager" method="getInstance" var="componentManager"/>

<!-- Get CustomFieldManager from ComponentManager -->
<core:invoke on="${componentManager}" method="getCustomFieldManager" var="customFieldManager"/>

<!-- Get CustomField object from customFieldManager -->
<core:invoke on="${customFieldManager}" method="getCustomFieldObjectByName" var="myField">
    <core:arg type="java.lang.String" value="My Field"/>
</core:invoke>

<!-- Get IssueManager from ComponentManager -->
<core:invoke on="${componentManager}" method="getIssueManager" var="issueManager"/>

<!-- Get the Issue from IssueManager -->
<core:invoke on="${issueManager}" method="getIssueObject" var="issueKey">
    <core:arg type="java.lang.String" value="${issue.key}"/>
</core:invoke>

<!-- Get Custom Field Value -->
<core:invoke on="${myField}" method="getValue" var="myFieldValue">
    <core:arg type="com.atlassian.jira.issue.IssueImpl" value="${issueKey}"/>
</core:invoke>

So there you have it. We're interacting with components that are part of JIRA's public API from within the script.

As of JIRA 5.2, most of the ComponentManager methods are deprecated, in favour of the ComponentAccessor. That makes our lives a git easier. If you are working with JIRA 5.2 and later, to get a reference to the CustomFieldManager, do this:

<!-- Get an instance of ComponentManager -->
<core:invokeStatic className="com.atlassian.jira.component.ComponentAccessor" method="getCustomFieldManager" var="customFieldManager"/>

To set the value of a custom field in an existing issue, you'll need to work with the OrderableField interface, which is implemented by CustomField; specifically the updateValue method. I'm sure you can work out the core:invoke commands for that.

0 votes
Fred Hauschel
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.
March 3, 2013

Hi,

don't now anything about jelly ;-)

But I have used a custom field in my velocity templates these days:

$customFieldManager.getCustomFieldObjectByName("Overall_start")

Maybe this helps!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events