Script content limitations
When you create a script that you want to execute in the Script Execution Service, for example, a script that an Orchestrator or Object Model API references, there are certain limitations that you must keep in mind.
The main script content restrictions relate to:
- Use of CommonJS
- Avoiding certain libararies and scripts
- Use of libraries and functions
- Memory limitations
Use of CommonJS#
In these scripts, the JavaScript syntax differs slightly from the syntax of a regular script in the Item Service. Because of this, you should use CommonJS for your script content.
Additionally, do not export functions. Instead use the function keyword for functions you want to export:
// local function const getAssetsData = async (input, libraries, context) => {
};
//exported function async function searchAssets(input, libraries, ctx) { return await getAssetsData(getQueryParams(input), libraries, ctx) }Avoiding certain libraries and scripts#
To avoid encountering errors, it is best not to use certain libraries and scripts. The main restrictions to be aware of are as follows:
- If you log the
librariesobject to the console, such as withconsole.logorconsole.info, it will throw an error. - The
URLSearchParamsJavaScript API does not work in platform scripts. - The following built-in JavaScript functions do not work in platform scripts and should be avoided:
setTimeout()clearTimeout()setInterval()clearInterval()setImmediate()clearImmediate()
Use of libraries and functions#
When using libraries, call platform library functions in your scripts with the await keyword. See example code below.
async function myFunction(libraries) { const { IafProj } = libraries.PlatformApi const proj = await IafProj.getCurrent(ctx) return proj }
You can use the packages listed below by destructuring them from the libraries parameter:
const { moment } = libraries; | Package | Documentation |
|---|---|
| PlatformApi | JavaScript Platform APIs |
| CoreUtils | Platform utility functions |
| ScriptEngineModule | Contains IafScriptEngine and IafDataPlugin libraries |
| ModelReader | Internally used for model import |
| fs | FileSystemWrapper |
| path | https://nodejs.org/api/path.html |
| unzipper | https://www.npmjs.com/package/unzip-stream |
| uuidv4 | https://www.npmjs.com/package/uuidv4 |
| _ | https://www.npmjs.com/package/lodash |
| moment.js | https://www.npmjs.com/package/moment |
| moment timezone | https://www.npmjs.com/package/moment-timezone |
| chrono node | https://www.npmjs.com/package/chrono-node |
| day js | https://www.npmjs.com/package/dayjs |
| mingo | https://www.npmjs.com/package/mingo |
| ajv | https://www.npmjs.com/package/ajv |
| http | This package has been removed, use fetch() instead. |
4.3 IAF package updates#
| Package | Changes |
|---|---|
| core-utils | Added DataXlsx |
| iaf-script-engine | Removed LocalCSVLoader and LocalFileLoader, and moved DataXlsx to core-utils |
| ui-utils | Moved DataXlsx to core-utils |
| IafDataPlugin | Available under 'scriptEngineModule' package, added saveWorkbookToFS and readWorkbookFromFS |
Global functions#
uploadToFilesvc#
Uploads a file on your local disk to the File Service
| Parameter | Required | Type | Description |
|---|---|---|---|
| filePath | Required | String | Relative file path |
| ctx | Optional | Ctx | Context, such as namespaces and authentication token information. |
| options | Optional | FileOptions | Pass a FileOptions object with your file options as properties, such as "headers", and "filename". |
const filePath = 'local/path/to/file.txt';const options = { filename: "document1"};
const response = await uploadToFilesvc(filePath, ctx, options);Fetch#
Native JS fetch API
| Parameter | Required | Type | Description |
|---|---|---|---|
| resource | Required | String or Object | Pass a Request object or a string or any other object with a stringifier, including a URL object, that provides the URL of the resource you want to fetch. The URL may be relative to the base URL, which is the document's baseURI in a window context, or WorkerGlobalScope.location in a worker context. |
| options | Optional | FileOptions | Pass a FileOptions object with your file options as properties, such as "headers", and "filename". |
const url = 'https://qa1-api.in.invicara.com/objectmodelsvc/api/information/version';try { //GET call const response = await fetch(url);
} catch(err) { //do something} //fetch with optionstry { const payload = {}; const requestOptions = { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) } const response = await fetch(url, requestOptions);} catch(err) { //do something} GetApplicationConfig#
The getApplicationConfig() function retrieves configuration data.
See example code below.
async function testConfig(input, libraries, ctx) { const appConfig = await getApplicationConfig() console.log('appConfig->', appConfig) return appConfig}Memory limitations#
The maximum size of a script execution response is 25 MB. If the response is larger than 25 MB, the script worker will return the following error message:
Script execution response is more than 25 MB!!.
For responses larger than 25MB, first upload it to the File Service and then download the response.
The system maintains a maximum of 5MB of the latest script execution logs.