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);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.