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!
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.
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!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.