This topic contains 14 replies, has 0 voices, and was last updated by khultquist 9 years, 7 months ago.

  • Author
    Posts
  • #24146

    adang

    Hi Everyone,

    I have written a scheduled suitescript code in which imports a csv and maps the variables at a certain time, given that the file already exists in the file cabinet and the ID is known.

    However, I still have not been able to find a way to upload a file to the file cabinet automatically. I'd like to be able to push a csv file from a local drive or ( server drive \serverdatabasepdmbook1.xls) to the file cabinet when changes are made to the file or new version is available ( Maybe use MSMQ to trigger a code to push the data from my PC to file cabinet?) . Would this be possible?

    I do not have that much of experience in JS or API, but very keen to learn.

    This is the code I have for scheduled import script:

    Code:
    function scheduledimporting(type){

    var csvMap = '15';
    var csvFile = nlapiLoadFile("5828"); //csv file id from filecabinet
    //************************************************** *************************************
    // originally thought of the below code to use and fetch data from a url but did not work
    // var urlrequest=nLapiRequestURL('https://………..',null,a);
    // var body=response.getBody(); //get the body of the message
    //************************************************** ***********************************
    var csvImport = nlapiCreateCSVImport();//creating a new csv import
    csvImport.setMapping(csvMap);//setting import map
    csvImport.setPrimaryFile(body.getValue());//file to be imported
    csvImport.setOption("jobName", "Test1111");
    var csvSubmitId = nlapiSubmitCSVImport(csvImport);//submitting the CSV

    Any help is appreciated.

    Thanks,
    This is a cached copy. Click here to see the original post.

  • #24147

    adang

    BUMP .

  • #24148

    srodriguez

    What error were you getting when trying to retrieve the file from a server location? I do see you have the API incorrectly formatted – should be nlapiRequestURL instead of nLapiRequestURL. That would definitely throw an error.

  • #24149

    adurangalvis

    I am also very interested in this, please if someone can help with this.

  • #24150

    teddycaguioa

    In order to upload a local file to the File Cabinet, you need to write a desktop program (for example .NET Forms). You then use web services to upload the files to the file cabinet.

  • #24151

    jwenzer

    Another option that I just got to work is to use the new Email Capture plug in. I am having our outside system that employees punch time email "Netsuite" a report every night, and now I can save the csv file to the file cabinet automatically! It works great.

    Does anybody know if there is a way after performing the nlapiSubmitCSVImport to have the system automatically email the response file so a user does not have to login in the morning to check the status of the import?

  • #24152

    khultquist

    jwenzer – was there any trick to getting the Email Capture plugin installed? I can't find it in suitebundle search.

  • #24153

    jwenzer

    I had the same issue. Turns out, if you are on 2015.1, you already have it! Go to Customization, Plug-ins, Plug-in Implementation, and you can create a new one of type Email Capture. You'll need to have your script file uploaded already that has the function to process the email. After creation, you get the Netsuite assigned Email Address to use

  • #24154

    khultquist

    Thanks for the help!

  • #24155

    khultquist

    I've run some successful tests with Email Capture. I have to say that I like the feature, but it seems incomplete, like it's still in beta:Very difficult to follow the implement instructions, because as of 2015.1 the plug-in is already installed in account (instructions tell you to install a bundle)
    Why is this a "plug-in" anyways? Shouldn't it just be part of suitecloud?
    No option to "Run as Administrator". You can choose the role "System Administrator", but that is not the same.
    To discover the incoming email address, you have to "implement", then "manage".
    To run the implementation, you have to check a box on the "manage" page, and it's not clear what this checkbox does. Apparantly it "enables" the plug-in implementation, but it would make more sense and be more consistent if this was a "deployment"
    The implementation should have the option to run other script functions, similar to how other suitescripts work. I cannot choose my function name, it must be "process(email)"

  • #24156

    wwinters

    I thought that the Email Capture feature might be a great way to import sales orders from an external system, like Ariba that sends orders via email as an XML attachment, but it seems that the Suitescript XML APIs are not implemented in the plug-in…

    When I loop thru the attachments and find the one of type XMLDOC, and then getValue() of the attachment for the raw XML and use nlapiSelectValue, I get the following error:

    Can't find method $Proxy105.nlapiSelectValue(string,string)

    Any luck using XML API's with the Email Capture plug-in?

    Thanks!

    Wes

  • #24157

    khultquist

    wwinters – In my account, I used Email Capture to simply move attachments to a designated File Cabinet folder. Once the files are there, I have a scheduled script that looks for files in that folder and imports them

    If your scripts work in regular suitescript, you could do something similar.

  • #24158

    wwinters

    Thanks for the quick reply!

    I'll save the file and process with a scheduled script then.

    Best,

    Wes

  • #24159

    wwinters

    OK, I have the file saved into a new folder I just created in the File Cabinet. How do I look for/loop through files in that folder in the scheduled script? I don't have the file ID.

    Thanks!

    Wes

  • #24160

    khultquist

    Here's a snippet of my script that searches a folder, then moves the file to a completed folder

    Code:
    var in_folder = 260191; // folder name = "ASN Incoming"
    var out_folder = 260192; // folder name = "ASN Completed"

    // *** Search Folder ***
    var filters = [];
    filters.push(new nlobjSearchFilter('folder', null, 'is', in_folder));
    var file_results = nlapiSearchRecord('file', null, filters);

    // *** Loop Thru Results ***
    for (var i in file_results) {
    var file_result = file_results[i];
    var fileId = file_result.getId();
    var file = nlapiLoadFile(fileId);
    var fileName = file.getName();
    var fileType = file.getType();
    var fileSize = file.getSize();
    var fileContents = file.getValue();

    }

    // *** Move File to Completed Folder ***
    if (!found_error) {
    var copiedFile = nlapiCreateFile(fileName, fileType, fileContents);
    copiedFile.setFolder(out_folder);
    nlapiSubmitFile(copiedFile);
    nlapiDeleteFile(fileId);
    }

You must be logged in to reply to this topic.