How can I perform a one-time bulk copy of system field values to a custom field?

Seems like it should be pretty straightforward, but I haven't found a way.  There seem to be similar questions on here, but not with answers.

If I have a filter with x-number of issues and want to copy a system field of date type to a newly created date field, how can that be done?  For new issues, it will be populated automatically by a post function, but for historic issues I haven't found a method to do this.

Script Runner only works for custom field to custom field.

2 answers

This script copies a value from one custom field to another.

I think you can modify it to your needs. It could be run from script console for scrit Runner. If it suits I can advice how to use it for set of issues

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.UpdateIssueRequest
import com.atlassian.jira.issue.fields.CustomField

/**
 * Script for copy value from one custom field to another
 */

IssueManager issueManager = ComponentAccessor.getIssueManager();
Issue issue = issueManager.getIssueByCurrentKey("SN458-1")
if (issue == null)
    return "No such issue"

//Prepare to update
UpdateIssueRequest.UpdateIssueRequestBuilder issueRequestBuilder = new UpdateIssueRequest.UpdateIssueRequestBuilder();
issueRequestBuilder.eventDispatchOption(EventDispatchOption.ISSUE_UPDATED);
issueRequestBuilder.sendMail(false);
UpdateIssueRequest updIssReq = new UpdateIssueRequest(issueRequestBuilder);

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();

CustomField cstFld_From = customFieldManager.getCustomFieldObjectByName("Name1");
CustomField cstFld_To = customFieldManager.getCustomFieldObjectByName("Name2");

if(     (cstFld_From == null)
    &&  (cstFld_To == null)
    &&  (cstFld_From.getCustomFieldType() != cstFld_To.getCustomFieldType()
    &&  (cstFld_From != cstFld_To)
    )) {
        issue.setCustomFieldValue(cstFld_To, cstFld_From.getValue(issue))
        issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser(), issue, updIssReq);
}

JIRA Command Line Interface (CLI) is often used for doing various bulk operations. In this case, you would use the copyFieldValue action. Front end that with runFromIssueList with a JQL that identifies all the issues you want to update. See How to use runFromIssueList if necessary.

Suggest an answer

Log in or Join to answer
Community showcase
Emilee Spencer
Published yesterday in Marketplace Apps

Marketplace Spotlight: DeepAffects

Hello Atlassian Community! My name is Emilee, and I’m a Product Marketing Manager for the Marketplace team. Starting with this post, I'm kicking off a monthly series of Spotlights to highlight Ma...

37 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot