Hello
I would like to migrate JIRA standard "label" field values to codecentric Label Manager thanks to Adaptavista Script Runner.
Codecentric documents its REST API but I am interested in "internal API" so that I can loop over issues in Groovy script...
Where could I find some groovy script examples for "Label Manager"?
Thank you in advance
Yves
Hello @Yves Martin
Did you try to copy values as it is?
codecentric labels must extends jira labels, so it must work.
import com.atlassian.jira.bc.issue.search.SearchServiceimport com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.issue.Issueimport com.atlassian.jira.issue.ModifiedValueimport com.atlassian.jira.issue.util.DefaultIssueChangeHolderimport com.atlassian.jira.jql.builder.JqlClauseBuilderimport com.atlassian.jira.jql.builder.JqlQueryBuilderimport com.atlassian.jira.web.bean.PagerFilterimport com.atlassian.query.Queryimport com.atlassian.jira.issue.search.SearchResultsimport org.slf4j.Loggerimport org.slf4j.LoggerFactory;Logger log = LoggerFactory.getLogger('update.labels')def changeHolder = new DefaultIssueChangeHolder();SearchService searchService =ComponentAccessor.getComponent(SearchService.class);def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()def cf_new = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('New Labels')JqlClauseBuilder builder = JqlQueryBuilder.newClauseBuilder()Query query = builder.project('IM').and().labels().not().labelsIsEmpty().buildQuery()SearchResults searchResult = searchService.search(user,query, PagerFilter.getUnlimitedFilter())List<Issue> res = searchResult.getIssues()String size = res.size()log.debug('Issues count: {}', size)log.debug('update started')int i = 1res.each { cf_new.updateValue(null, it, new ModifiedValue(it.getCustomFieldValue(cf_new), it.getLabels()),changeHolder); log.debug('Issue {} was updated. {} of {} issues', it.getKey(), i, size) i++}log.debug('update ended')
For the record, I have map each label to custom field specific value:
def labels = [ ] as Setissue.getLabels().each { labels += customField.getCustomFieldType() .getSingularObjectFromString(it.toString())}def changeHolder = new DefaultIssueChangeHolder()customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), labels), changeHolder)
But I am not satisfied with it, as no "change group" / history is visible on issue yet.
If interested, refers to https://community.atlassian.com/t5/Jira-questions/ScriptRunner-How-to-build-HistoryMetadata-for-an-issue/qaq-p/856609
Hello @Yves MartinIf you want store changes in change history, you should use set methods of MutableIssue and IssueManager update method that stores changes
issue.setLabels("your labels")ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
Please check this article Three-ways-to-update-an-issue-in-Jira-Java-Api
You find all you need there
Thanks for that reference. "customField.updateValue" is the only method that does not save a history changeset on issue.
It looks like you're new here. Sign in or register to get started.