We are trying to consolidate project-specific custom description fields into the 'Description' system field to have a streamlined workflow.
I have read through this existing question about copying system field to custom field, but I cannot get it to work in the other direction: https://community.atlassian.com/t5/Jira-questions/copying-values-of-System-field-to-Custom-field/qaq-p/610962
I believe I've found the correct methods to use by following the answers in this other question:
I'm able to get the data from the custom field, but this isn't updating the system field. Could someone help point out how I'm messing up the final line parameters, or if I'm missing some additional input:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.bc.issue.IssueService
import org.apache.log4j.Logger
import org.apache.log4j.Level
log.setLevel(Level.DEBUG)
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def query = jqlQueryParser.parseQuery("project = PACE AND summary ~ testscriptrunner") // change query to match the issues you want to update
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter()) // get results of query
results.getIssues().each {documentIssue -> // go through each issue
def issue = issueManager.getIssueObject(documentIssue.id)
log.debug("----------------------")
log.debug(documentIssue.key)
log.debug("Current Description Value: " + documentIssue.description)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName("Story Description");
def newValue = issue.getCustomFieldValue(customField)
log.debug("Current Story Description Value: " + newValue)
def issueService = ComponentAccessor.getIssueService()
def issueInputParameters = issueService.newIssueInputParameters()
//customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), documentIssue.description),new DefaultIssueChangeHolder()); // copy description to story description - working
issueInputParameters.setDescription("newValue"); //copy story description to description - not working
}
I'm not receiving any error, it just won't update the Description even when setting a dummy value
I was able to complete a working script. This will iterate through all issues in the search query to copy "Story Description" custom field to "Description" system field. This should be easy to update to copy any CUSTOM field to a SYSTEM field.
Scriptrunner shows an error at line 36, but it doesn't seem to cause any issue.
Hope this can help someone else:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.search.SearchProvider
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.bc.issue.IssueService
import org.apache.log4j.Logger
import org.apache.log4j.Level
log.setLevel(Level.DEBUG)
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def query = jqlQueryParser.parseQuery("project = TEST AND component = \"KT/Roll out\"") // change query to match the issues you want to update - escape quotes in query with \
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter()) // get results of query
results.getIssues().each {documentIssue -> // go through each issue
def issue = issueManager.getIssueObject(documentIssue.id)
log.debug("----------------------")
log.debug(documentIssue.key)
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def customField = customFieldManager.getCustomFieldObjectByName("Story Description");
def newValue = issue.getCustomFieldValue(customField)
def issueService = ComponentAccessor.getIssueService()
def issueInputParameters = issueService.newIssueInputParameters()
issueInputParameters.setDescription(newValue); //copy story description to description
//Copying data and Validating Update
def updateValidationResult = issueService.validateUpdate(user, issue.getId(), issueInputParameters);
if(updateValidationResult.isValid()) {
def updateResult = issueService.update(user, updateValidationResult);
log.error("Update Result Done without error. Assignee is " + updateResult.getIssue().getAssignee());
}else{
log.error("Update Validation Result not Valid.");
}
}
Rather than scripting, couldn't you export the Description and Custom field into CSV, then use Excel to combine them into one field, then import again to update the Description?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That was actually the first approach I took but, when importing from csv, all of the formatting was lost. Line breaks, bullets, text format is all gone - it just imports as an unformatted single line.
Is there a way to import and keep the formatting?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, unfortunately not, as CSV import is just plain text. You might be able to import HTML markup, but I've never tried it...
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.
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.