How can I get csv data in netsuite?

I have a question for my question. I really wanted to know the following: How to get csv data in netsuite? It looks like I'm using the csv import tool to create a mapping and use this call to import csv nlapiSubmitCSVImport (nlobjCSVImport).

Now my question is: how do I iterate over an object ?! This gives me half way - I get csv data, but I can't figure out how I repeat it to manipulate the date. This, of course, is the whole point of the planned script.

It really drives me crazy.

@Robert H I can think of millions of reasons why you want to import data from CSV. Billing, for example. Various reports on the data stored in any company, and I would not want to save them in the file cabinet, and I would not want to save the file at all. I just need data. I want to manipulate him, and I want to introduce him.

+4
source share
3 answers

Solution Steps:

  • To load a CSV file, we must use the Suitelet script.

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

     var fileField = form.addField('custpage_file', 'file', 'Select CSV File'); var id = nlapiSubmitFile(file); 
  • Get ready for the Restlet script call 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'; 

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

  • Let's call Restlete with nlapiRequestURL :

     // Calling Restlet var output = nlapiRequestURL(url, recordText, headers, null, "POST"); 
  • Create a mapping by importing CSV records, available under Settings> Import / Export> Import CSV Records.

  • Inside the Restlet script Extract the file identifier from the Restlet parameter. Use the nlapiCreateCSVImport() API and set its mapping to the display identifier created in step 3. Install 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. 
  • Submit using nlapiSubmitCSVImport() .

     nlapiSubmitCSVImport(job); // We are done 

There is another way that we can get around this, although it is not preferable and do not propose. (since it consumes a lot of APIs if there are a large number of entries in your CSV file.)

Say we donโ€™t want to use the nlapiCreateCSVImport API, so let's continue from step 4.

  • Just enter the file identifier, as we did earlier, upload the file and get its contents.

     var fileContent = primaryFile.getValue(); 
  • Separate the lines of the file, then separate the words and store the values โ€‹โ€‹in 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]); } } 

    Note. Make sure that there is no extra blank line in the CSV file.

  • Finally, create a record and set the 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 
+3
source

A NetSuite user friend here, I've been using SuiteScripts for a long time, but have never seen an nlobjCSVImport or nlapiSubmitCSVImport object. I looked in the documentation, it shows, but there is no page describing the details, share where you got the document from?

With the document for the CSVImport object, I could provide additional help.

PS I tried to post this post as a comment, but the Add Comment link did not appear for some reason. Still new to SOF

0
source

CSV for JSON:

If you know the structure of the CSV file, just do a for loop and map the fields to the corresponding nlapiSetValue.

It should be pretty simple.

0
source

Source: https://habr.com/ru/post/1433432/


All Articles