Invoke a Script Function from Another Script Referenced as Script Library
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:
- Library Script File, that will be called(Invoked/consumed) - sample and creation steps:
- 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.
- Go toCustomization > Scripting > Scripts > New
- In the Script File field, enter a name for the script record and then clickCreate Script Record.
- Select the script type (i.e. Scheduled).
- 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:
Steps and code - Main Script - library consuming script:
- Go toCustomization>Scripting>Scripts>New
- Script Filefield: Enter a name for the script record
- ClickCreate Script Record
- Select the script type (i.e. Suitelet).
- Fill in all the required fieldson the Script record (Name field in the body fields - i.e. MainScript.js)
- Navigate toScript>Scripts> set Script File and Function
- Libraries > LIBRARY SCRIPT FILE : reference the Library Script File(i.e. InvokedLibrary.js) created in point 1. > Add > Save