Skip to main content
Version: v4.6

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#

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 libraries object to the console, such as with console.log or console.info, it will throw an error.
  • The URLSearchParams JavaScript 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; 
PackageDocumentation
PlatformApiJavaScript Platform APIs
CoreUtilsPlatform utility functions
ScriptEngineModuleContains IafScriptEngine and IafDataPlugin libraries
ModelReaderInternally used for model import
fsFileSystemWrapper
pathhttps://nodejs.org/api/path.html
unzipperhttps://www.npmjs.com/package/unzip-stream
uuidv4https://www.npmjs.com/package/uuidv4
_https://www.npmjs.com/package/lodash
moment.jshttps://www.npmjs.com/package/moment
moment timezonehttps://www.npmjs.com/package/moment-timezone
chrono nodehttps://www.npmjs.com/package/chrono-node
day jshttps://www.npmjs.com/package/dayjs
mingohttps://www.npmjs.com/package/mingo
ajvhttps://www.npmjs.com/package/ajv
httpThis package has been removed, use fetch() instead.

4.3 IAF package updates#

PackageChanges
core-utilsAdded DataXlsx
iaf-script-engineRemoved LocalCSVLoader and LocalFileLoader, and moved DataXlsx to core-utils
ui-utilsMoved DataXlsx to core-utils
IafDataPluginAvailable under 'scriptEngineModule' package, added saveWorkbookToFS and readWorkbookFromFS

Global functions#

uploadToFilesvc#

Uploads a file on your local disk to the File Service

ParameterRequiredTypeDescription
filePathRequiredStringRelative file path
ctxOptionalCtxContext, such as namespaces and authentication token information.
optionsOptionalFileOptionsPass 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

ParameterRequiredTypeDescription
resourceRequiredString or ObjectPass 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.
optionsOptionalFileOptionsPass 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}   

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.