Converse agora com nosso suporte
Chat com o suporte

Foglight 5.9.2 - Web Component Guide

Introducing the Web Component Framework The Web Component Framework Configuring Views and Context Queries Functions Bindings Additional Components

Using Functions

Similar to queries, Functions are called as a binding, in this case the Function binding. For more information, see Bindings.

Functions as Converters

A function can be marked as a Converter. A Converter is a function that takes data of one type as input and converts it to data of another type.

A registry is automatically kept of such Converters and components can request a Converter for an input/output type when needed.

Only functions that take a single (non-List) input and that have a single (non-List) output are allowed to be Converters. Only one Converter can be registered for a given pair of input/output types. If there are many Converters that can handle an input/output type pair, only the most recently loaded one will be registered and a warning message will be logged. Converters are loaded upon start up of the system, or when a module is imported/deleted, or when a Function is edited and saved.

Caching results of Functions

If a Function is referred to in Additional Context, the result value of the Function may be calculated many times (due to how View Components are initialized).

If you know that your Function will output the same value given the same Time Range and Function parameters, then you can avoid the redundant calculations by checking the Cache Results checkbox in the Function editor for the Function Definition in question.

Information available from a Script, Script with Map or Java Function

From within a JavaTM, Script or a Script with Map Function, a special FunctionHelper class is available for accessing additional information. See the javadoc for that class for more details on what information is available.

For Java Functions, FunctionHelper objects are passed as a parameter to the specified Java method.

For Script or Script with Map Functions, the FunctionHelper class is accessible through the reserved script parameter, functionHelper. To make things easier, the argument values of function parameters can also be accessed by directly referencing the name of the parameter. The reserved script parameters are also available:

resourceBundle: The Java Resource Bundle for the current locale with strings loaded from the module’s file strings.properties (uploaded using the Files tab available under Configuration > Definitions).
specificTimeRange: The current SpecificTimeRange. This value should always be passed when you access property values of any time-sensitive data object. For example:
To get property b, instead of writing:

Since these parameter names are reserved, they cannot be used as the name for declared Script or Script with Map Function parameters. The reserved script parameters should be referenced using the same notation used for other script parameters.

For Java Functions, these are available via the corresponding getter methods of the FunctionHelper parameter. The table shows the methods in FunctionHelper:

createDataObject(
String typeName, String storage,
String objectId)

Creates a writable data object.

getArguments()

Returns a Map containing the argument values for the function's parameters.

getLocale()

Returns the user locale.

getResourceBundle()

Returns the ResourceBundle for the current Locale, loaded from the strings.properties file in the module to which the function belongs.

getSpecificTime
Range()

Returns a SpecificTimeRange whose start/end dates are computed based on the TimeRange when the function was invoked.

getTimestamp()

Returns the current timestamp.

getUser()

Returns the name of the current user.

getUserModule
Name()

Returns the name of the user module.

getViewId()

Returns the ID of the view for the current view component.

invokeFunction(
String fqId,
Object... arguments)

Invokes a function. Used for invoking a function within another function.

invokeQuery(
String fqId,
Object... arguments)

Invokes a query.

Documentos relacionados

The document was helpful.

Selecione a classificação

I easily found the information I needed.

Selecione a classificação