Script Optimization

Jira Code: TRS-386

The relevance of the post is to optimize the performance and boost the speed of the system we build. Many a time, we encounter situations where saved searches have to be loaded in forms.

Forms are made of Suitelets. Usually, the saved searches for the front end validation is done in Clientscripts. But this can have an impact adversely on the performance of the forms. In such cases, we can make use of another technique to load saved searches in Suitelet and then pass it to Clientscript.

Steps

  1. Create a form using Suitelet script type.
  2. Create an Inline HTML field type.
  3. Do the search in Suitelet and load it to this Inline HTML field (to the window) using the script tags.
  4. When the form is loaded, the search in the field will be accessible for further coding in Clientscript through the window object. (The window object is supported by all browsers. It represents the browser’s window. All global JavaScript objects, functions, and variables automatically become members of the window object. Global variables are properties of the window object. Global functions are methods of the window object.)
  5. We can store the saved search results in any data structure and use them accordingly.

Example

Suitelet

var main = {

onRequest: function() {

var form = serverWidget.createForm({ title: ‘Charity Assessment’ });

var allSubsidiaries = form.addField({
id: “custpage_allsubsidiaries”,
type: “INLINEHTML”,
label: “TRS-386 Subsidiary Obj”
});
allsubsidiries.defaultValue = ‘<script>window._SYSTEM_DEFINED_SUBSIDIARIES_=’ + JSON.stringify(dataSet.getAllSubsidiaries()) + ‘;</script>’;

context.response.writePage(form);

}

}

// Here dataSet.getAllSubsidiaries() is a function that returns the results of all subsidiaries available in the system in an object structure.

Clientscript

var main = {

pageInit: function(scriptContext) {

var allSubsidiaryObj;

allSubsidiaryObj = window.SYSTEM_DEFINED_SUBSIDIARIES;

}

}

// Use allSubsidiaryObj to refer all the subsidiaries in the system.

If we had tried to load the saved search in Clientscript from scratch, that could have lead to massive loading of the form and affect the user experience.

Leave a comment

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