Browsed by
Tag: netsuite

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.

11 Secret Suitescript 2.1 Features That Reptilians Don’t Want You To Know

11 Secret Suitescript 2.1 Features That Reptilians Don’t Want You To Know

Suitescript 2.1 is out of beta and beginning on 2021.1 release all Suitescript 2.x scripts will be running as Suitescript 2.1 so better test your existing scripts for any bugs.

To change your scripts to use Suitescript 2.1 all you have to do is change this JSTag:

From:

To:

It’s also worth mentioning that as of today Suitescript 2.1 is not available for client scripts yet so bear that in mind.


“let” keyword:

This is basically a super local variable, it’s very useful for using them in for loops. Now you can have multiple nested for loops and declare all of your loop counter variables “i” and not worry about conflicts.

Example

Using var:

Using let:

For details check out w3schools.

 


“for of” statement

This is another way to loop through an array, I find it easier to write although it only works on iterables so this means it doesn’t work on objects as opposed to “for in” which works on both objects and arrays.

Example

Considering:

Using “for in”:

Using “for of”:

This looks more elegant to me, but you be the judge.

For details check out w3schools.


String includes() Method

If you are like me and hate the sight of using .search() or regex to check if a string includes some text then you need this in your life.

Example

Considering the following string:

Using search method:

Using includes method:

So your code would end up looking like this:

Holy molly, this was long overdue. I love this and will be using it very oftenly.

For details check out w3schools.


Array includes() Method

This is the same thing as the previous example with String includes() method. I find it easier and more elegant than using Array indexOf.

Example

Considering the following string:

Using indexOf method:

Using includes method:

For details check out w3schools.


Array every() Method

This method is useful for validating if all of the elements of the array meet certain condition, if one of them doesn’t meet the condition then it returns false.

Example

For details check out w3schools.


Set Object

The set object is a list of unique values of any type. This is very useful for removing duplicates from an Array.

Example

Here’s another example

It has several methods you can use like: add, size, has, forEach, delete and clear so it makes a powerful tool by itself. Sets also outperforms Arrays so that’s another reason to love it.

For details check out Alligator.io and  Mozilla Docs.


Spread syntax

This is basically used to expand an array or compact several parameters into an array.

Examples

Useful for concatenating two arrays like:

Or making copies of arrays like:

For details and more uses check out Scotch.io and  Mozilla Docs.


Template literals (Template strings)

This is a life changer. You can now use backtick characters (`)  to have more freedom when defining strings, they also support placeholders and multi-line strings!

Example

Using string concatenation:

Using template literals:
The output is the same:
For details and more uses check out Mozilla Docs.

 


Arrow functions

These functions work the same as regular functions but have a more compact syntax.

Example

Regular function:

Arrow function:

And it can get even shorter:

Anonymous arrow function with params:
For details and more uses check out w3schools.

Serverside promises

Promises are now supported serverside so you can now write asynchronous code.

Example

You can also create your own Promises now like so:

For details and more uses check out Mozilla Docs.

 


Async functions (Async/Await)

Async functions provide a way to structure and simplify your asynchronous code. I find this very useful to avoid callback hell that comes with Promises as it can get pretty complex, I have seen some code where there’s an unending statements of .then.then.then….. in a row.

Example

For details and more uses check out Mozilla Docs.

 


 

So what do you think? Do you agree with our list? Share your comments below.