Collect Function

The collect method allows including all the JSON files (files in JavaScript Object Notation format) with a defined name in all the libraries. This function requires the name of the file as individual parameter. It carries out a search in all the libraries for any files that have the specified name; it will then perform a multiple dynamic object parsing. Such operation is dynamic because it depends on the libraries that are installed when the function is executed. If a library is added to the project, the collect method may return multiple results.

Syntax

It is possible to search all the Scripts library blocks by name and collect JSON files for the defined name. See the following syntax:

var export = collect(<fileName>)

Parameters Usage

Parameter

Type

Default

Use

Annotation

fileName

String

-

Mandatory

Name of the JSON file to be searched for the dynamic inclusion.

Result

The result of the collect operation returns an array of the parsed objects returned by the specific Scripts library blocks searched by name.

Error Handling

Errors can occur in case:

  • No parameters are passed to the collect function. When the script is saved, the following error displays in the Error List expander:
    • Invalid or missing parameters in the method.

Examples of Use

How to use the collect method for retrieving all the JSON files named "Data" in all the libraries

Create a JSON file named “Data” to be imported into one or multiple libraries. For example:

{

    "library": "Global_Scripting",

    "info": "Information about this JSON file",

    "min": -1.4,

    "max": 6

}

 

Create a script to retrieve information from all the JSON files with name “Data”. For example:

var dataObjects = collect("Data");

console("Found {0} data files", dataObjects.length);

for (var i = 0; i < dataObjects.length; i++)

{

    console("-----------------");

    console("Library: {0}", dataObjects[i].library);

console("Library: {0}", dataObjects[i].info);

console("Library: {0}", dataObjects[i].min);

console("Library: {0}", dataObjects[i].max);

}

 

When executing the script, the result of the execution is:

Found 1 files

File num 1

Library: Global_Scripting