We implement NetSuite with world-class passion and professionality, making the experience with the #1 ERP cloud software even more awesome.

Migrate an entry point function from SuiteScript 1.0 to 2.x

This is a follow-up on our previous post where we have announced the release of a process for migrating any script from SS1 to SS2 without re-implementing the logic (https://www.ketka.eu/2021/08/03/migrate-from-suitescript-1-0-to-2-x-in-the-blink-of-an-eye/).

The signature of the entry point functions changes between SuiteScript 1 and 2. Parameters object types of SS1 don't exist in SS2, and vice versa.

For this reason, when migrating an entry point function from SS1 to SS2 we need some adjustments in order to avoid re-writing any code.

Let's take for example a Before Load entry point function of a User Event script, and consider this simplest pseudo-code snippet:

function beforeLoad(type, form, request) {
  // Do something, using parameters "type", "form" and "request".
  // This can be any very complex set of operations and calls to sub-functions.
  [...]
}

For using the same whole code without any change, and migrate the script to SS2 using our tools, the pseudo-code is adjusted as follows:

function beforeLoad(context) {
  // Re-create the SS1 entry point parameters
  var type = context.type;
  var form = new nlobjForm({ss2Form: context.form});
  var request = new nlobjRequest({ss2Request: context.request});
  
  // Call the old (unchanged) entry point function
  oldBeforeLoad(type, form, request);
}

function oldBeforeLoad(type, form, request) {
  // Do something, using parameters "type", "form" and "request".
  // This can be any very complex set of operations and calls to sub-functions.
  [...]
}

Some explanations on how it practically works:

  • the "type" parameter is just a string, and can be directly obtained by the context.type property
  • the "form" parameter is a SS1 object, and in our re-implementation of it in SS2 we allow to create a new instance passing a SS2 form object as input. This object works exactly as in the original SS1 implementation.
  • regarding the "request" parameter, the same applies as to the "form" parameter

Important: we might need to use the SS2 "context" parameter somewhere else in our code, assuming that we want to develop it further after the migration.
In order to not change every JS function in the stack from the entry point till where we need to use it, the migrated code can access a global object where the "context" entry point parameter has been stored.
The available global objects vary depending on the script type and context.

In this article we have analyzed a Before Load example, the same logic can be applied for migrating any other entry point function and script type.

alessio |
August 30, 2021

Leave a Reply

Your email address will not be published. Required fields are marked *