Hi, I'm taking the value of "MyCustomField" field, using this script.
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObjectByName("MyCustomField")
def cFieldValue = issue.getCustomFieldValue(cField)
so and I have other custom field e.g. ("TestCustomField"). How can I set value of cFieldValue to "TestCustomField" using groovy script?
The easiest way to accomplish this will depend on where you want to execute that script.
For example, if a workflow Post Function, you just need to
def cField2 = customFieldManager.getCustomFieldObjectByName('TestCustomField')
issue.setCustomFieldValue(cField2, cFieldValue)
This will work as long as the 2 fields are of the same type and your Post Function is before the built-in function that stores the issue.
If you want to do this elsewhere, like in a listener, then you need to take care of storing and indexing the updated issue.
def cField2 = customFieldManager.getCustomFieldObjectByName('TestCustomField')
issue.setCustomFieldValue(cField2, cFieldValue)
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
issueManager.updateIssue(currentUser, issue,EventDispatchOption.DO_NOT_DISPATCH, false)
def indexingService = ComponentAccessor.getComponent(IssueIndexingService.class)
boolean wasIndexing = ImportUtils.isIndexIssues();
ImportUtils.setIndexIssues(true);
indexingService.reIndex(issue)
ImportUtils.setIndexIssues(wasIndexing);
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.