Copy system field values to custom in bulk?

There is a built-in script which allows to copy custom field values from one field to another in bulk. Is there the same possibility to copy values from system field to custom? E.g. from Due to DateCustomField ?

1 answer

0 vote
Vasiliy Zverev Community Champion Jun 20, 2016

Here is a code example:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.project.Project

/**
 * Move date value from one custom field to another
 */

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField dateFrom = customFieldManager.getCustomFieldObjectByName("field name 1");
if(dateFrom == null)
    return "field for date from not found"

CustomField dateTo = customFieldManager.getCustomFieldObjectByName("field name 2");
if(dateFrom == null)
    return "field for date from not found"

//Loop issues and update
IssueManager issueManager = ComponentAccessor.getIssueManager();
for(Project project: ComponentAccessor.getProjectManager().getProjectObjects())
    for(MutableIssue issue: issueManager.getIssueObjects( issueManager.getIssueIdsForProject())){
        issue.setCustomFieldValue(dateTo, issue.getCustomFieldValue(dateFrom))
        issue.setCustomFieldValue(dateTo, issue.getDueDate()) //if you want to copy from due
        issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getUser().getDirectoryUser(), issue, EventDispatchOption.ISSUE_UPDATED, false)
    }

Hi Vasiliy,
Thank you for the answer! Sorry I am late with my reply.
Do I need to copy your example of a code, then paste it into the Script Console and click the Run button?
I just never did this operation.

With kind regards
Vyacheslav

Vasiliy Zverev Community Champion Jun 28, 2016
  1. Test it on test JIRA instance.
  2. Yes, you need just to cope it to a script console
  3. Try also to perfom it at first not on all project/issues, but only on sigle peoject/issue
  4. Good luck!

I see you are novice, since ask more questions here.

 

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Wednesday in Jira

Join our webinar: How 1B+ feature flag events helped us build the new Jira

Every time you release software, there's a bit of risk – that there's a bug, that something breaks, or that the feature doesn't resonate with customers. Feature flagging helps make high stakes s...

91 views 0 1
Join discussion

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