copy custom field (text) to affects version

Hi - I'm trying to import data from Redmine into JIRA.  After the import, I have a custom field (text) that contains the value for Affects Version.  How do I copy this custom field into Affects Version?  JIRA support asked me to look into ScriptRunner, bur I'm not seeing how to yet

3 answers

1 accepted

This widget could not be displayed.

I think the idea here is that you import the text field as text initially, and then write a script that you can run as a one-off that will read the field on each issue, find (or create) a matching version for it in the project and then set the affects version to it.  Then delete the text field as you don't need it any more.

This widget could not be displayed.

Got it!  Instead of using updateIssue, I had to use updateIssueAffectsVersions:

versionManager.updateIssueAffectsVersions(issue, affectsVersions);
        	//issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue, EventDispatchOption.ISSUE_UPDATED, false);
This widget could not be displayed.

Hi Nic - I tried your suggestion but am still stuck at setting the affectsVersion field. This is the code I have:

import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.project.version.Version;
import com.atlassian.jira.project.version.VersionImpl;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.event.type.EventDispatchOption;
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager;
import java.util.ArrayList;
import java.util.Collection;
def projectManager = ComponentAccessor.getProjectManager()
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def vfi = customFieldManager.getCustomFieldObjectByName("jiramigration_vfi")
Project project = projectManager.getProjectByCurrentKey("APPMGR");
Collection<Long> projectIssueIds = issueManager.getIssueIdsForProject(project.getId());
log.warn(" Init2 ");
Collection<Version> projVers = project.getVersions();
projVers.each {
    log.warn(it.getProject());
    log.warn(it.getDescription());
    log.warn(it.getId());
    log.warn(it.getName());
}
projectIssueIds.each {
    Issue issue = issueManager.getIssueObject(it);
    Collection<Version> affectsVersions = issue.getAffectedVersions();
    def cur_vfi = issue.getCustomFieldValue(vfi);
    String cur_val = cur_vfi.toString();
    if (affectsVersions == null || !affectsVersions.size()) {
        affectsVersions = new ArrayList<Version>();
        Version verToLog;
        projVers.each {
            if (it.getName() == cur_val)
            {
                log.warn(" Match --- " + it.getName() + " " + cur_val);
                verToLog = it;
            }
        }
        if (verToLog != null)
        {
        	log.warn(" Ver Name " + verToLog.getName());
            affectsVersions.add(verToLog);
        	issueManager.updateIssue(ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(), issue, EventDispatchOption.ISSUE_UPDATED, false);
        }
   }
    
}

The script runs w/o errors, but the issue does not show the affects Versions field populated.  

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

421 views 3 17
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