Validator not affecting while importing data from csv file

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

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.

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
Community showcase
Published Jan 08, 2019 in Jira

How to Jira for designers

I’m a designer on the Jira team. For a long time, I’ve fielded questions from other designers about how they should be using Jira Software with their design team. I’ve also heard feedback from other ...

1,092 views 4 9
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