Validator not affecting while importing data from csv file

SUNIL SABALE December 27, 2015

I am trying to import vendor list from csv. While creating Issue as Vendor name I have applied validator for existing vendor name. It is affecting while creating vendor manually. But it is not affecting while creating vendor while importing from csv

 

2 answers

1 vote
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 27, 2015

CSV imports bypass all validation other than "summary is mandatory".  You'll need to get your data correct in the source CSV, rather than rely on whatever your validators do.

0 votes
Vasiliy Zverev
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.
December 27, 2015

You could use some script to import issues. I used this script to import a lot of issues from some source (~ 2 000 issues). It could be executed via ScriptRunner. I merged requlred values into a strings with "#" separtor from all sources, parced it into script and create issues. 

import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueInputParameters
import com.atlassian.jira.project.Project
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.util.ErrorCollection

/**
 * Скрипт по заливке запросов из файла Excel
 */

String[] splitedImpStr = new String[3];
final String prjKeyPrefix = "MSC"
String result = "";

ApplicationUser curAppUser = ComponentAccessor.jiraAuthenticationContext.getUser();
ProjectManager prjMng = ComponentAccessor.getProjectManager();

//подготавливаем создание запроса
IssueService issueService = ComponentAccessor.getIssueService();
IssueInputParameters inputParameters = issueService.newIssueInputParameters();

//Цикл по созданию запросов
for(String curImportedStr: getStringsForImport()){
    splitedImpStr = curImportedStr.split("##")

    if(getValue(splitedImpStr[2]).equals(""))
        continue;

    Project curPrj = prjMng.getProjectObjByKey(prjKeyPrefix + getPrjNmb(splitedImpStr[1]));
    if(curPrj == null)
        return "Проект не найден"

    inputParameters.setProjectId(curPrj.getId())
    .setIssueTypeId("10903")
    .setSummary("Еженедельный отчет")
    .setReporterId("vzverev")
    .setAssigneeId(curPrj.getLeadUserKey())
    .setEnvironment("Enviroment")
    .setStatusId("6")
    .setPriorityId("2")
    .setDueDate(getDueDate(Integer.parseInt(getValue(splitedImpStr[0]))))
    .addCustomFieldValue(10807, getValue(splitedImpStr[2]));

    IssueService.CreateValidationResult createValidationResult = issueService.validateCreate(curAppUser, inputParameters);
    ErrorCollection errorCollection = createValidationResult.getErrorCollection();
    result = errorCollection.toString();

    if(createValidationResult.isValid()){
        IssueService.IssueResult createResult = issueService.create(curAppUser, createValidationResult);

        if(!createResult.isValid())
            return "Bad"
    }
}

return result;

public String getDueDate(int _week){
    Calendar dueDate = Calendar.getInstance();
    dueDate.set(Calendar.WEEK_OF_YEAR, _week);

    return dueDate.get(Calendar.DAY_OF_MONTH) + "/" + (dueDate.get(Calendar.MONTH) + 1) + "/" + dueDate.get(Calendar.YEAR);
}

public int getPrjNmb(String _forParsing){
    String prjNmb = "";
    for(Character ch: getValue(_forParsing))
        if( ch.isDigit() )
            prjNmb += ch;

    return Integer.parseInt(prjNmb);
}

public String getValue(String _input){
    return _input.substring(_input.indexOf("=") + 1, _input.length())
}

public List<String> getStringsForImport(){
    List<String> stringsForImport = new ArrayList<String>();




    return stringsForImport;
}

Suggest an answer

Log in or Sign up to answer