我如何将csv数据导入netsuite? [英] How go I get csv data into netsuite?

查看:178
本文介绍了我如何将csv数据导入netsuite?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题有了更新。
我真正想知道的是:
如何将csv数据导入netsuite?
嗯,似乎我使用csv导入工具来创建一个映射并使用这个调用来导入csv nlapiSubmitCSVImport(nlobjCSVImport)。

I've got an update to my question. What I really wanted to know was this: How do I get csv data into netsuite? Well, it seems I use the csv import tool to create a mapping and use this call to import the csv nlapiSubmitCSVImport(nlobjCSVImport).

现在我的问题是:我如何遍历对象?!
这让我走了一半 - 我得到了csv数据,但我似乎无法找出如何迭代它以操纵日期。当然,这是预定脚本的重点。

Now my question is: How do I iterate through the object?! That gets me half way - I get the csv data but I can't seem to find out how I iterate through it in order to manipulate the date. This is, of course, the whole point of a scheduled script.

这真让我生气。

@Robert H
我可以想到你想要从CSV导入数据的一百万个原因。比如,例如。关于任何公司保留的数据的各种报告,我不想将其保留在文件柜中,我也不想真正保留文件。我只想要数据。我想操纵它,我想输入它。

@Robert H I can think of a million reasons why you'd want to import data from a CSV. Billing, for instance. Various reports on data any company keeps and I wouldn't want to keep this in the file cabinet nor would I really want to keep the file at all. I just want the data. I want to manipulate it and I want to enter it.

推荐答案

解决方案步骤:


  1. 要上传CSV文件,我们必须使用Suitelet脚本。

  1. To upload a CSV file we have to use a Suitelet script.

(注意: file - 此字段类型仅适用于Suitelet,并将显示在Suitelet页面的主选项卡上。将字段类型设置为file会在页面上添加文件上载窗口小部件。)

(Note: file - This field type is available only for Suitelets and will appear on the main tab of the Suitelet page. Setting the field type to file adds a file upload widget to the page.)

var fileField = form.addField('custpage_file', 'file', 'Select CSV File');
var id = nlapiSubmitFile(file);


  • 让我们准备调用Restlet脚本并将文件ID传递给它。

  • Let's prepare to call a Restlet script and pass the file id to it.

    var recordObj = new Object();
    recordObj.fileId = fileId;
    
    // Format input for Restlets for the JSON content type
    var recordText = JSON.stringify(recordObj);//stringifying JSON
    
    // Setting up the URL of the Restlet
    var url = 'https://rest.na1.netsuite.com/app/site/hosting/restlet.nl?script=108&deploy=1';
    
    // Setting up the headers for passing the credentials
    var headers = new Array();
    
    headers['Content-Type'] = 'application/json';      
    headers['Authorization'] = 'NLAuth nlauth_email=amit.kumar2@mindfiresolutions.com, nlauth_signature=*password*, nlauth_account=TSTDRV****, nlauth_role=3';
    

    (注意: nlapiCreateCSVImport :此API为仅支持捆绑安装脚本,预定脚本和RESTlet)

    (Note: nlapiCreateCSVImport: This API is only supported for bundle installation scripts, scheduled scripts, and RESTlets)

    让我们使用 nlapiRequestURL 调用Restlet :

    Let's call the Restlet using nlapiRequestURL:

    // Calling Restlet
    var output = nlapiRequestURL(url, recordText, headers, null, "POST");
    


  • 使用设置>导入/导出>导入CSV记录中的导入CSV记录创建映射。

  • Create a mapping using Import CSV records available at Setup > Import/Export > Import CSV records.

    在Restlet脚本中从Restlet参数中获取文件ID。使用 nlapiCreateCSVImport() API并使用在步骤3中创建的映射ID设置其映射。使用 setPrimaryFile() function。

    Inside the Restlet script Fetch the file id from the Restlet parameter. Use nlapiCreateCSVImport() API and set its mapping with mapping id created in step 3. Set the CSV file using the setPrimaryFile() function.

    var primaryFile = nlapiLoadFile(datain.fileId);
    var job = nlapiCreateCSVImport();
    job.setMapping(mappingFileId); // Set the mapping
    
    // Set File
    job.setPrimaryFile(primaryFile.getValue()); // Fetches the content of the file and sets it.
    


  • 使用提交nlapiSubmitCSVImport()

    nlapiSubmitCSVImport(job); // We are done
    


  • 那里我们可以解决这个问题的另一种方式,虽然既不优选也不建议。(因为如果您的CSV文件中有大量记录,它会消耗大量的API。)

    There is another way we can get around this although neither preferable nor would I suggest. (As it consumes a lot of API's if you have a large number of records in your CSV file.)

    假设我们不想使用 nlapiCreateCSVImport API,那么让我们从步骤4继续。

    Let's say that we don't want to use the nlapiCreateCSVImport API, so let's continue from the step 4.


    1. 只需像我们之前那样获取文件ID,加载文件并获取其内容。

    1. Just fetch the file Id as we did earlier, load the file, and get its contents.

    var fileContent = primaryFile.getValue();
    


  • 拆分文件的行,然后拆分单词并将值存储到单独的数组。

  • Split the lines of the file, then subsequently split the words and store the values into separate arrays.

    var splitLine = fileContent.split("\n"); // Splitting the file on the basis of lines.
    
    for (var lines = 1,count=0; lines < splitLine.length; lines++)
    {
        var words = (splitLine[lines]).split(","); // words stores all the words on a line
    
        for (var word = 0; word < words.length; word++)
        {
            nlapiLogExecution("DEBUG", "Words:",words[word]);
        }
    }
    

    注意:确保没有额外的CSV文件中的空行。

    Note: Make sure you don't have an additional blank line in your CSV file.

    最后从我们上面创建的数组中创建记录并设置字段值。

    Finally create the record and set field values from the array that we created above.

    var myRec = nlapiCreateRecord('cashsale'); // Here you create the record of your choice
    
    myRec.setFieldValue('entity', arrCustomerId[i]); // For example, arrCustomerId is an array of customer ID.
    
    var submitRec = nlapiSubmitRecord(myRec); // and we are done
    


  • 这篇关于我如何将csv数据导入netsuite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆