Function Elements

Prev Next

Functions are elements that define a block of code with a returning value, which can be used inside expressions and properties across the project. Each function contains a script that is executed every time the function is invoked. Functions can also call other functions, which promotes code reusability and modularity. By breaking tasks down into smaller, more manageable functions, you can create code that is flexible and easier to maintain.

In Web Vision, functions can be called using the expression ‘func(“name of the function”, parameter 1, parameter2… parameter N)’, where "name of the function" represents the name given to the template of the function being called, and parameter1 to parameterN represent the parameters passed to the function.

  1. Project tree: Within the Functions folder, new functions can be created, and existing functions are listed there. Functions tree admit folders grouping, .

  2. Properties tree: ‘Script’ property contains the script developed for the function. The input helper will trigger the Expression editor, showing the code of the function, if any was previously written. This property can only be modified from this pop up.

  3. Line count and code folding markers.

  4. Expression editor with automatic syntax highlighting.

  5. Helpers button bar.

  6. Buttons for loading files with JavaScript code, from an external source. Additionally, there is a button to save the expression and another button to discard the changes.

When calling this function, which multiplies the array [1, 2, 3, 4] (argv[0]) by 3 (argv[1]), it returns the array [3, 6, 9, 12].

Error returned by calling the function because not all arguments are provided, only the name of the function, but the function requires argument 1 (argv[0]) to be an array and argument 1 (argv[1]) to be a number.

In this example, we showcase a function named utils_formatDate.

This function retrieves a timestamp (denoted by 'ts') from a specified tag path ('argv[0]'). It then converts this timestamp to a time zone-aware datetime using the Moment.js library, which is bundled with N3uron. Finally, it formats the datetime according to the provided date format ('argv[1]').

In the animated image provided, you will see a practical demonstration of this function's usage. In this example, we invoke the utils_FormatDate function, passing two arguments: argv[0], a tag full path, and argv[1], a string representing the desired date format to be applied to the timestamp. The function internally retrieves the timestamp from the tag and subsequently returns it with the specified format.FunctionDateFormat

Web Vision Full Product Details