Browsed by
Tag: netsuite

Boost Efficiency: Convert Large Netsuite CSVs to Excel XLSX

Boost Efficiency: Convert Large Netsuite CSVs to Excel XLSX

I faced a challenging project that involved converting large CSV files stored in Netsuite’s file cabinet into XLSX format, specifically in Excel files. These files varied in size, with some exceeding 30 MB and even 100 MB. Initially, I attempted to use SheetJS, a plugin designed for this purpose (https://docs.sheetjs.com/docs/demos/cloud/netsuite/). However, I encountered difficulties as the plugin loaded the entire CSV file into memory, causing errors and performance issues.

To overcome this limitation, I devised an alternative solution for converting the CSV files to Excel XLSX format. My approach involved iterating through the CSV file line by line and constructing the XLSX file from scratch. Leveraging the fact that XLSX files are essentially zip files containing multiple XML files, I successfully accomplished the conversion. As a result, not only were the CSV files successfully converted, but the resulting XLSX files also demonstrated significant reductions in file size. In some cases, file sizes were reduced by up to 50%.

However, it is important to be aware of certain caveats associated with this conversion method. There are instances where the size of the resulting ZIP file becomes too large to compress, leading to a failure in the conversion process and triggering a timeout error. The exact threshold for this issue is not specified, as I have encountered failures with files around 50 MB, while others as large as 200 MB were processed without any problems. Consequently, it is crucial to consider the possibility of encountering heavy files that may not be compatible with this code. For optimal processing power, it is advisable to execute the code as a Schedule/Mass Reduce script.

 

To utilize the function effectively, ensure you are running it on Suitescript 2.1 and that the following modules are loaded: “N/xml,” “N/file,” and “N/compress.”

Simply provide the function with the File Cabinet path of the CSV file, and it will seamlessly transform it into an Excel file, preserving both the original file name and folder location.
Eg:

 

Suitescript 2.0 SFTP Tool

Suitescript 2.0 SFTP Tool

One of the new features of SuiteScript API 2016.2 is the ability to connect to SFTP Servers directly from Netsuite.

Here are some downsides I found:

  • Not way to list the contents of a remote directory <– This has been added
  • No way of connecting using a private key. <– This has been added
  • Not all SFTP servers are supported as Netsuite requires the server to support some encryption algorithms.
  • No way of obtaining the server’s hostkey natively.

 

Unfortunately the process is a bit confusing if you are new to the SFTP world so I created a tool that will help you jump-start your script. I found this tool very useful as I was able to test an SFTP connection quickly for a client and turned out the SFTP server that they were trying to use didn’t actually support Netsuite’s approved algorithms (aes256-ctr, es192-ctr, es128-ctr), so it saved me a lot of time as I was able to quickly discard it and move on.

I also included an endpoint to get the HostKey of the URL you are trying to connect to. I think this will be very useful for people who don’t have a Linux server lying around where they can run ssh keyscan.

Note: The HostKey endpoint should be used to grab the hostkey and store it elsewhere on your end. Do not use the endpoint to request the hostkey every time you make a request. If your server HostKey changes very frequently then I suggest to build your own tool.

Here’s a video tutorial:

https://www.youtube.com/watch?v=azxo7GS3xRQ

 

And here’s the code ready to be uploaded as a Suitelet, have fun!:

Suitescript 2.0 Quickstart Examples

Suitescript 2.0 Quickstart Examples

Here I will be posting the most used scripts from Suitescript 2.0. These code examples are meant for beginners to be a quick start so they can quickly get a script started and add their code to them. I tried to keep them short. If you are a beginner I recommend you to check Netsuite’s Help section and navigate to Suitescript 2.0 API so you can learn more about each.

 


Client Script

Note: Check out how the helper functions in clientscript have to be nested inside the main runClientscript function. This is something particular to client scripts.


User Event Script


Scheduled Script


Suitelet


RESTlet

Leave a comment if you want to see other examples.