I'm importing some projects from Fogbugz to Jira, and as part of the import cleanup I want to convert some of the custom fields Atlassian's importer brought over to comments on the issues. Elsewhere on Answers, I found a snippet of a groovy script to set the Description system field from a custom field; I took that snipped and I can change setDescription to setComment, and change the name of their custom field to mine, but I don't want to do this as part of a workflow, I need to do this post-import. So for instance, for all projects and customfield XYZ is not empty, I want to copy customfield XYZ to comments. After the script runs (and updates say, 5000 issues) I intend on deleting the custom fields, then doing the next import of 50 projects.
Here's the snippet I have so far:
IssueInputParametersImpl inputParameters = new IssueInputParametersImpl(); inputParameters.setComment("Custom Field XYZ"); inputParameters.addCustomFieldValue(sourceCustomField, ""); validateResults = issueService.validateUpdate(user, issue.getId(), inputParameters); if (validateResults.isValid()) { issueService.update(user, validateResults); }
How would I wrap that in a query and then iteratively go through the results and do that script snippet?
Or, am I going about this all wrong? Any other suggestions?
-Kelly
Your going about it right but you have a way to go... here's some code to get you started. Requires testing, and error handling:
import com.atlassian.jira.bc.issue.search.SearchService import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.jql.parser.JqlQueryParser import com.atlassian.jira.web.bean.PagerFilter import org.apache.log4j.Logger def log = Logger.getLogger("com.onresolve.jira.groovy.MyScript") def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class) def query = jqlQueryParser.parseQuery("project = jra ") // query as you would enter in to issue nav def searchService = ComponentAccessor.getComponent(SearchService.class) def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() def results = searchService.search(user, query, PagerFilter.getUnlimitedFilter()) def issueManager = ComponentAccessor.getIssueManager() def commentManager = ComponentAccessor.getCommentManager() def customFieldManager = ComponentAccessor.getCustomFieldManager() def customField = customFieldManager.getCustomFieldObjectByName("BillableStatus") // name of CF results.getIssues().each {issue -> def mutableIssue = issueManager.getIssueObject(issue.id) commentManager.create(mutableIssue, user.name, /*comment body:*/ issue.getCustomFieldValue(customField) as String, false ) }
This is excellent, thank you very much. It may be quick and dirty, but it worked well. A sample run on our sandbox jira had it find & update 235 issues in under 2 seconds.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Cool. One piece of advice... I think it might be better to append all the custom field values you don't want to keep to the description. You can use wiki markup to put them in a nice table.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
we have a ServiceDesk customfield of the "Request Participants" fieldtype.
Is there a script solution to copy the values to the system field watchers?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Doing it with a service is fine, it's the "proper" way. My way below is the quick and dirty way. You can wrap your code inside the issues loop in my example if you prefer.
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.