Home > Net >  CANT_FIND_SAVED_IMPORT, Can't import CSV file
CANT_FIND_SAVED_IMPORT, Can't import CSV file

Time:10-27

I have got an error every time, this is because the mappingId is wrong, where I need to create/get mappingId? any solution.

{"type":"error.SuiteScriptError","name":"CANT_FIND_SAVED_IMPORT","message":"No saved import with internalId 123","stack":["createError(N/error.js)","<anonymous>(adhoc$-1$debugger.user:13)","<anonymous>(adhoc$-1$debugger.user:1)"],"cause":{"type":"internal error","code":"CANT_FIND_SAVED_IMPORT","details":"No saved import with internalId 123","userEvent":null,"stackTrace":["createError(N/error.js)","<anonymous>(adhoc$-1$debugger.user:13)","<anonymous>(adhoc$-1$debugger.user:1)"],"notifyOff":false},"id":"","notifyOff":false,"userFacing":false}
require(["N/task","N/file"],function(task,file){

    var fileObj = file.create({
        name:"temporary.csv",
        fileType:file.Type.CSV,
        contents: "1,1"
    });

    var obj = task.create({taskType: task.TaskType.CSV_IMPORT});
    obj.mappingId = 123; 
    obj.importFile = fileObj;
    obj.name = "TestingCSV";
    var objId = obj.submit();
    log.debug(objId);
});

CodePudding user response:

You need to manually create the mapping first by navigating to Setup > Import/Export > Import CSV Records.

Select your file, map your columns then Save and Run the import. This will create a CSV mapping that you can reference in your script. You can get the mapping ID by navigating to Setup > Import/Export > Saved CSV Imports.

CodePudding user response:

Do as Mike Robbins said and y edit your script you need to save the file first to get the internalid of the file

require(["N/task","N/file"],function(task,file){

    var fileObj = file.create({
        name:"temporary.csv",
        fileType:file.Type.CSV,
        contents: "1,1"
    });

var fileObjID=fileObj.save();

    var obj = task.create({taskType: task.TaskType.CSV_IMPORT});
    obj.mappingId = 123; 
    obj.importFile = fileObjID;
    obj.name = "TestingCSV";
    var objId = obj.submit();
    log.debug(objId);
});
  • Related