• ERP Support
      • Netsuite System Status
  • Quicta Support
Submit a Request
Login
  • Home
  • /
  • Jcurve Support Articles
  • /
  • Invoke a Script Function from Another Script Referenced as Script Library
Jcurve Support Articles / Setup & Customisation

Invoke a Script Function from Another Script Referenced as Script Library

Written by
Manuelito Macalinao
Published on
September 28, 2023 at 7:40:10 AM PDT September 28, 2023 at 7:40:10 AM PDTth, September 28, 2023 at 7:40:10 AM PDT

Scenario

User can call (invoke) a Script library function by another script packing the generic functionality of the code as Library.

Note:This process applies only to SuiteScript 1.0. For detailed instructions on how this functionalityshould be handled within SuiteScript 2.0, see article51781 SuiteScript 2.x Custom Modules.

Solution

Sample steps and code to achieve this:

  1. Library Script File, that will be called(Invoked/consumed) - sample and creation steps:
    1. Go toCustomization > Scripting > Scripts > New

      *Note that after creating your script record, you can later access the record by going toCustomization > Scripting > Scriptsto see a list view of all Script records.

  2. In the Script File field, enter a name for the script record and then clickCreate Script Record.
  3. Select the script type (i.e. Scheduled).
  4. Fill in all the required fields on the Script record - 'Name' field(i.e. InvokedLibraryScript.js) in the body fields and under 'Scripts', specify the 'SCRIPT FILE'(i.e. InvokedLibrary.js) and 'FUNCTION'(i.e. findMax)

***Important NOTE*** - reference nothing in 'Libraries', as this will be the Library itself> Add > Save


Library script sample:
functionfindMax(){var i;var max =-Infinity;for(i =0; i < arguments.length; i++){if(arguments[i]> max){ max = arguments[i];}}return max;}//Load and return the project-job loaded function loadProjectJobByID() { oProject = nlapiLoadRecord('job', arguments[0], { recordmode : 'dynamic' }); return oProject; } //sample usage of JavaSctipr build-in 'arguments' object function ParamentersWithNoNames() { var result; nlapiLogExecution('Debug', 'arguments.callee ', 'arguments.callee =' + arguments.callee); nlapiLogExecution('Debug', 'arguments.caller ', 'arguments.caller =' + arguments.caller); nlapiLogExecution('Debug', 'arguments.caller ', 'arguments.length =' + arguments.length); if (arguments.length == 2) { result = arguments[0] + arguments[1]; } else { result = 'Invalid parameters!!!'; } return result; } //sample usage of Named Paramenters - Parameters are tested before performing the operation function ParamentersWithNames(x, y) { var result; if (y === undefined) { result = 'y is undefined'; } if (x === undefined) { result = result + 'x is undefined'; } if (result !== undefined) return result; else { result = x + y; } return result; }



Steps and code - Main Script - library consuming script:
  1. Go toCustomization>Scripting>Scripts>New
  2. Script Filefield: Enter a name for the script record
  3. ClickCreate Script Record
  4. Select the script type (i.e. Suitelet).
  5. Fill in all the required fieldson the Script record (Name field in the body fields - i.e. MainScript.js)
  6. Navigate toScript>Scripts> set Script File and Function
  7. Libraries > LIBRARY SCRIPT FILE : reference the Library Script File(i.e. InvokedLibrary.js) created in point 1. > Add > Save
{nlapiLogExecution('Debug','Script Execution begin ','Script Invoker begin');//Invoke findMax()var retValue =findMax(1,100,1000,1001,42);//print the result of invokationnlapiLogExecution('Debug','retValue is ','retValue is :'+ retValue);//Invoke the loadProjectJobByID()var retCustomer =loadProjectJobByID(571);//Print the ProjectJob'ID in the ExcutionLogsnlapiLogExecution('Debug','retValue is ','retCustomer is :'+ retCustomer.id);//Invoke and print-result of ParamentersWithNoNames()nlapiLogExecution('Debug','retValue is ','ParamentersWithNoNames is :'+ParamentersWithNoNames(3,1));//Invoke and print-result of ParamentersWithNames()nlapiLogExecution('Debug','retValue is ','ParamentersWithNames is :'+ParamentersWithNames(2,3));//Script completion logging linenlapiLogExecution('Debug','Script Invoker end','Script Invoker end');}
#script
#suitescript
#script library
#Invoke
Jcurve Support Articles / Setup & Customisation
Back to Top

Stay connected

  • Quick Links

  • About
  • Products
  • Services
  • Industries
  • Insights
  • Referral
  • Privacy Policy | Terms & Conditions
  • ERP & TEMS Agreement
  • Quicta Agreement
© 2025 Jcurve Solutions