This topic contains 12 replies, has 0 voices, and was last updated by dmashburn3 7 years, 10 months ago.

  • Author
    Posts
  • #6041 Score: 0

    dmashburn3
    • Contributions: 0
    • Level 1

    Hi,

    This is my first try at running a CSV Import from a file attached to a case. I’m having no trouble pulling the file with a saved search, but I keep getting:

    “UNEXPECTED ERROR during CSV Import process” on nlapiSubmitCSVImport()

    Here is what I’m working with:

    Code:
    function importCsvFile(){
    var messageSearch = nlapiSearchRecord(“message”,null,
    //start by setting up criteria
    [
    [“subject”,”contains”,”ITEMIMPORT”],
    “AND”,
    [“messagedate”,”within”,”today”]
    ],
    //and then the results page
    [
    new nlobjSearchColumn(“internalid”,”attachments”,null)
    ]
    );
    for (var i=0;i< =messageSearch.length-1; i++){ nlapiLogExecution('debug','test',i); var fileId = messageSearch[i].getValue('internalid','attachments',null); nlapiLogExecution('debug','fileId = ',fileId); var import = nlapiCreateCSVImport(); import.setPrimaryFile(nlapiLoadFile(fileId)); import.setMapping('CUSTIMPORTImportItemMapping'); import.setOption('jobName','itemImport'); var importId = nlapiSubmitCSVImport(import); nlapiLogExecution('debug','importId = ',importId); } } Can anyone explain this error? Thanks ​
    This is a cached copy. Click here to see the original post.

  • #6042 Score: 0

    dmashburn3
    • Contributions: 0
    • Level 1

    Also, just to be more clear, the fileId is coming back correct, and the script is executing and says “Complete”, but the execution log shows:
    importId =

    UNEXPECTED ERROR during CSV Import process

  • #6043 Score: 0

    david.smith
    • Contributions: 0
    • Level 1

    Best way to do CSV imports from script is to first save the CSV Import as a working saved import. You can then just dump your data right to it. Keeping in mind the 25,000 row limitation.

  • #6044 Score: 0

    dmashburn3
    • Contributions: 0
    • Level 1

    Oh, strange, I thoughts that is what I was doing with the field:

    import.setMapping(‘CUSTIMPORTImportItemMapping’);

    That is the name of the import that I saved. Should I be calling it differently?

  • #6045 Score: 0

    david.smith
    • Contributions: 0
    • Level 1

    Try commenting out the jobName option and change your import.setPrimaryFile(nlapiLoadFile(fileId)); to

    Code:
    import.setPrimaryFile(fileId);

  • #6046 Score: 0

    dmashburn3
    • Contributions: 0
    • Level 1

    I tried this line earlier (and just tried again with the setOption commented out) and got this result:

    SSS_INVALID_CSV_CONTENT – Input string is not valid CSV content.

    I don’t know why it wouldn’t accept fileId, but would accept the nlapiLoadFile(fileId). It seems like they would be the same thing?

  • #6047 Score: 0

    david.smith
    • Contributions: 0
    • Level 1

    try nlapiLoadFile(fileId).getValue()

  • #6048 Score: 0

    dmashburn3
    • Contributions: 0
    • Level 1

    That took me back to square one:

  • #6049 Score: 0

    david.smith
    • Contributions: 0
    • Level 1

    I just realized “import” is reserved. Try using “job” or something else for your import var.

  • #6050 Score: 0

    dmashburn3
    • Contributions: 0
    • Level 1

    That really felt like it was going to be it.

    Same thing though.

  • #6051 Score: 0

    dmashburn3
    • Contributions: 0
    • Level 1

    Could it be centered around having this set up as a scheduled script? Would that be a problem?

    I’m trying to think of any other context that could be causing it. Drawing blanks.

  • #6052 Score: 0

    david.smith
    • Contributions: 0
    • Level 1

    HA! Look what I found:

    Code:
    Warning: You should execute setMapping(savedImport) before any of the other methods. If you try to first execute setPrimaryFile(file), an error is returned.

    I’m stumped unless you have your “CUSTIMPORTImportItemMapping” ID misspelled or something.

    That import does already exist as a saved import, correct? You’re not trying to create it on the fly are you?

  • #6053 Score: 0

    dmashburn3
    • Contributions: 0
    • Level 1

    That did it!!!

    How did you find that warning?!?!

    Interesting that you set the mapping first in the script and then the file, but in the UI its the file and then the mapping.

    Thanks so much!

You must be logged in to reply to this topic.