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.SearchService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.jql.builder.JqlClauseBuilder
import com.atlassian.jira.jql.builder.JqlQueryBuilder
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.query.Query
import com.atlassian.jira.issue.search.SearchResults
import org.slf4j.Logger
import 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 = 1
res.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 Set
issue.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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Yves Martin
If 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 :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for that reference. "customField.updateValue" is the only method that does not save a history changeset on issue.
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.