Hello,
In our JIRA5 setup we set "Resolved" "Version Picker" custom field. I need to set "Resolved" custom field for all existing issues. And here is the fragment of groovy script which should do this
ComponentManager componentManager = ComponentManager.getInstance() IssueManager issueManager = componentManager.getIssueManager() def optionsManager = ComponentManager.getComponentInstanceOfType(OptionsManager.class) def customFieldManager = componentManager.getCustomFieldManager() def cfResolved = customFieldManager.getCustomFieldObjectByName("Resolved") Issue issue = issueManager.getIssueObject("PROG-1234") def fieldResolved = cfResolved.getRelevantConfig(issue) System.out.println("Previous Resolved On is : " + issue.getCustomFieldValue(cfResolved)); def optionResolved = optionsManager.getOptions(fieldResolved).find {it.value == "2011"} parent.setCustomFieldValue(cfResolved, optionResolved) System.out.println("Current Resolved On is : " + issue.getCustomFieldValue(cfResolved));
The Resolved custom field was not updated in the bug. The last println return correct "2011" value even it's not set for the bug.
In setCustomFieldValue documentation I found that
"Sets a custom field value on this Issue Object, but does not write it to the database. This is highly misleading. "
Could you please advise what method can I use in order to modify custom field value?
Thank you.
Cheers, Georgiy
You could use code like this to set a custom field:
MutableIssue issue CustomField cf def newValue def currentValue = issue.getCustomFieldValue(cf) def mValue = new ModifiedValue(currentValue, newValue) def iChangeHolder = new DefaultIssueChangeHolder() cf.updateValue(null, issue, mValue, iChangeHolder) // Maybe the following is not needed for 5.x
boolean wasIndexing = ImportUtils.isIndexIssues() // be sure indexing is on ImportUtils.setIndexIssues(true) issueIndexManager.reIndex(issue) ImportUtils.setIndexIssues(wasIndexing)
newValue has to be the same class as the result of getCustomFieldValue (here Option).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you!
I made it as you advised, i.e.
def newValue = issue.getFixVersions() def currentValue = issue.getCustomFieldValue(cfResolved) def mValue = new ModifiedValue(currentValue, newValue) def iChangeHolder = new DefaultIssueChangeHolder() cfResolved.updateValue(null, issue, mValue, iChangeHolder) boolean wasIndexing = ImportUtils.isIndexIssues() // be sure indexing is on ImportUtils.setIndexIssues(true) issueIndexManager.reIndex(issue) ImportUtils.setIndexIssues(wasIndexing) System.out.println("Current Resolved On is : " + issue.getCustomFieldValue(cfResolved));
and Resolved custom field contain the fix Version, but last println still shows previous currentValue. it's minor misbehavious but log contains wrong information then.
Do you know how I can get right logs, please?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you have to get the issue object again, e.g. by issueManager.getIssueObject(issue.id). I think it's a good idea to do this before the reindex takes place, after the updateValue()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you!
I had to get the issue object , and create new variable again after reindexing
boolean wasIndexing = ImportUtils.isIndexIssues() ImportUtils.setIndexIssues(true) issueIndexManager.reIndex(issue) ImportUtils.setIndexIssues(wasIndexing) // added only for the proper log Issue issueObjForLog = issueManager.getIssueObject(issueId) System.out.println("Current Resolved On is : " + issueObjForLog.getCustomFieldValue(cfResolved));
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.