CSV Import Query Issue field values (Multi-Select)

Adam Barylak
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 18, 2014

Hi, I am trying to import values along with new issues or update existing issues in JIRA and set the Multi-select Query Issue Field with values.  However, i haven't been able to get it to work.  It "completes" the import, then i look at the issue, and the field is shown in view mode, but is completely blank.  I have tried by using multiple columns for each issue i want to link, also by using a comma separated value in a single column and also a semi-colon separated value in a single column.  I have also tried a single issue key and also a single issue id value.  None of these options have worked for me.

Can someone please help me get these values imported.  We have thousands of issues we need to create or update with values for this field and do not want to do this manually.

I am using the "Query issue multi linker custom field" and the autocomplete view.

Let me know if you need any more information from me.  Thanks.

2 answers

1 accepted

0 votes
Answer accepted
Adam Barylak
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 4, 2016

Geoff-

Sorry for not answering sooner.  I did figure out a way to get the values into JIRA.  However, it is not with the CSV import.  I use the Scriptrunner plugin and have a one-off script that I run and it pulls information from a pre-defined CSV file to update the issues in JIRA.  Basically the CSV has 2 columns (JIRAIssueKey, LinkedIssueKeys).  For my use case, my LinkedIssueKeys are "Related Requirements" and they are separated with a semicolon.  Then, I place the csv file on the JIRA server in the following location and file name: "C:\Files\RelatedReqsImport.csv".  Then, I run the below script in the ScriptRunner Script Console.  I hope this helps with your import needs.  Thanks.

 

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.bc.issue.search.SearchService
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.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.index.IssueIndexManager
import com.atlassian.jira.issue.search.SearchException
import com.atlassian.jira.issue.search.SearchResults
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.web.bean.PagerFilter
import org.apache.log4j.Level
import org.apache.log4j.Logger
/**
 * Created with IntelliJ IDEA.
 * User: abarylak
 * Date: 9/19/14
 * Time: 8:45 AM
 * To change this template use File | Settings | File Templates.
 */
def log = Logger.getLogger("com.onresolve.jira.groovy.OneOffScripts.RelatedRequirementsImportFromCSV")
//log.setLevel(Level.DEBUG)
log.setLevel(Level.ERROR)
log.debug("Starting Related Requirements Import from CSV script")
SearchService searchService = ComponentAccessor.getComponentOfType(SearchService.class);
User currentUser = ComponentAccessor.getJiraAuthenticationContext().getUser().directoryUser;
IssueManager issueManager = ComponentAccessor.issueManager;
IssueIndexManager issueIndexManager = ComponentAccessor.issueIndexManager;
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField relatedReqs = customFieldManager.getCustomFieldObjectByName('Related Requirement/s');
List<Long> issuesToUpdate = new ArrayList<Long>();
List<String> reqsToUpdate = new ArrayList<String>();
new File("C:\\Files\\RelatedReqsImport.csv").splitEachLine(","){fields ->
    log.debug('Issue Key: ' + fields[0]);
    log.debug('Related Reqs: ' + fields[1]);
    String[] reqs = fields[1].split(';');
    for(String req : reqs){
        if(!reqsToUpdate.contains(req))
            reqsToUpdate.add(req);
    }
    Collection<String> newValue = reqs.toList();
//    newValue.clear();
    MutableIssue issue = issueManager.getIssueObject(fields[0]);
    if(issue != null){
        issue.setCustomFieldValue(relatedReqs,newValue);
        issueManager.updateIssue(currentUser, issue, EventDispatchOption.DO_NOT_DISPATCH, false);
        // re-index issue
        issuesToUpdate.add(issue.getId());
    }else
        log.error("ERROR: Bad issue found: " + fields[0]);
//    for(String req : reqs){
//        //build array of values to add to issue
//        log.debug('Value: ' + req);
//    }
    //set field value on issue
    //update issue
}
for(Long id : issuesToUpdate){
    if(id != null){
        boolean wasIndexing = ImportUtils.isIndexIssues();
        ImportUtils.setIndexIssues(true);
        log.debug("Reindex issue ${issueManager.getIssueObject(id).key}")
        issueIndexManager.reIndex(issueManager.getIssueObject(id))
        ImportUtils.setIndexIssues(wasIndexing)
    }
}

 

 

0 votes
Geoff Wilson
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 16, 2015

have you come up with any solution to this? I've been trying to figure this out for a week as well

Suggest an answer

Log in or Sign up to answer