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

This widget could not be displayed.

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.

This widget could not be displayed.
Vasiliy Zverev Community Champion Dec 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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted yesterday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

55 views 1 0
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