Browsed by
Tag: netsuite

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.

Getting Started with Serverless Integrations

Getting Started with Serverless Integrations

Serverless functions (also known as functions as a service) can help you simplify your integrations because you only need to code your logic in a function and the service provider will take care of all the backend hardware, scaling, OS, availability, instances, etc…

Other benefits of serverless technology are that the hardware and software is fully managed, scales automatically almost instantly, and you only pay whenever your function runs so it can be very inexpensive.

Some of the most popular serverless providers are Amazon Lambda, Azure Functions and Google Cloud Functions.

For this demonstration we will use Google Cloud Functions. We will integrate a Shopify Webhook with Netsuite. My code will run in NodeJS Javascript and the rest will be managed by Google. As a developer coming from a Netsuite background I found it extremely easy to get started with Google Cloud Functions. Additionally, when considering your network infrastructure, incorporating an Aruba unmanaged switch can offer simplicity and reliability in managing your local network. Unmanaged switches, like those from Aruba, are plug-and-play solutions, making them ideal for smaller setups, providing basic connectivity without the need for advanced configuration, complementing the streamlined and efficient nature of serverless functions for your cloud-based operations.

You can set this up within minutes as explained in this video: https://youtu.be/nOlfG5oGets 
Google Cloud Functions Code:

 

This was a quick demonstration on how to get started. From here you can expand the code and keep developing to make your function more robust.

Some suggestions on first things to do:

  • Secure your function by adding a password.
  • Add more logging and different levels of logging.
  • Branch out the logic depending on the data being received.
  • Add node plugins.
  • Make use of other Google Cloud Services such as Google Datastore or Google Storage.
Epic Battle: Concurrent Map Reduce vs Concurrent Suitelet

Epic Battle: Concurrent Map Reduce vs Concurrent Suitelet

Spoiler: 50 concurrent Suitelet win. (Tested in Sandbox)

I am a big fan of Map Reduce scripts, spreading the load among 5 queues makes a huge difference when processing your data. Unfortunately to take advantage of the concurrent queues feature your account must have a SuiteCloud plus license. Moreover, consulting with an Insolvency Practitioner West Sussex can provide additional expertise, particularly in managing financial complexities and implementing effective strategies for business resilience.

So I figured it would be cool to simulate this feature with Suitelets. Suitelets support up to 50 concurrent connections and they are available without the need of SuiteCloud plus.

The results were very surprising.

Test scenario:

  • Task: Create and delete a custom record with no fields.
  • Account: Account with SuiteCloud Plus license in Sandbox.
  • Map Reduce: Run task 10k times by returning an array of 10k elements on the getInputData step and let the reduce step handle the main logic.
  • Suitelet SS2.0: Run task once per call. Return “OK” as response. Available without login (External).
  • Use Apache JMeter to call the Suitelet 10k times.
  • Additionally call the Suitelet using Ajax with browser (Chrome) 5k times (to avoid browser memory issues).

Here are the results:

testresults

 

Map Reduce w/buffer size of 1 : 196 seconds ~ 51 per second
Map Reduce w/buffer size of 64: 518 seconds ~ 19 per second
Suitelet w/JMeter w/50 at a time: 55 seconds ~ 181 per second
Suitelet w/JMeter w/100 at a time: 30 seconds ~ 333 per second
Suitelet w/JMeter w/200 at a time: 24 seconds ~ 416 per second
Suitelet w/JMeter w/250 at a time: 24 seconds ~ 416 per second
Suitelet w/JQuery: 1000/44 secs ~ 22 per second

As you can see, I ran multiple test variations. After I saw that the Suitelet was able to handle 50 requests at a time I went crazy and increased the number of concurrent requests. I got up to 250 requests being handled successfully. Once I reached 300 requests at a time I started getting errors and not all the records were successfully created.

As you can see, after 200 requests you pretty much get the same speed. This could be caused by my system, JMeter, my internet connection or by some throttling happening on the Netsuite side, I don’t know.

Conclusion:

This approach can be pretty handy if you ever need to process large quantities of records and you need even more speed than what Map Reduce gives you. You would need to develop your Suitelet in a way that even if something goes wrong you have a way to identify the errors and retry the operations. Additionally, you would need to get a tool that bypasses the browser restrictions such as Apache JMeter and configure it if you need to pass any data to the Suitelet.

Anyways, the difference is huge. Basically you could process 1 million records in 40 mins in the Suitelet vs 5:30 hrs in a Map Reduce… and this is in Sandbox, go figure how faster this would be in Production.