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 to get the selected value from a custom field select type using Jelly Script?


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

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"/>

<!-- 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}"/>

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

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.


don't now anything about jelly ;-)

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


Maybe this helps!

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Marketplace Apps & Integrations

Expose your beautifully crafted Dashboard through the Jira Service Desk Customer Portal

  A picture is worth a thousand words, especially when you're trying to find relationships and understand your data. Here, Dashboards play a vital role in gaining insights from a variety of dat...

284 views 5 4
Read article

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