XFDL function calls

You can use XFDL function calls to design forms that include complex computations and calculations. XFDL function calls include: string functions, math functions, utility functions, time and date functions, header and footer functions, and bidirectional functions.

The Extensible Forms Description Language (XFDL) is an assertion-based language. Assertion-based languages include an engine that maintains statements in the code as true. The functions described in this section allow an XFDL form to perform procedural operations that would normally require complicated computations to achieve.

Function calls run code that can be external to the XFDL form definition. under are the BNF rules for functions.

	 FunctionCall := (LibName '.')? FunctionName '(' (Compute 
      (',' Compute)*)? ')'

	 LibName ::= sid 

	 FunctionName ::= sid

The LibName allows functions to be grouped into separate namespaces, but the predefined functions in this specification do not require a LibName. The LibName assigned to these predefined functions is system. Viewer functions enable form developers to trigger actions in the Viewer from within a form. The Viewer functions are compiled into a package called viewer, similar to the XFDLsystem package. Any user-defined package must contain an underscore in its name.

Examples

Calling a predefined function in the system namespace:

   <custom:status xfdl:compute="toggle(field1.value, 'high', 'low')">
   </custom:status>

or

   <custom:status xfdl:compute="system.toggle(field1.value, &#xA;
      'high', 'low')"></custom:status>

Calling a function in the viewer namespace:

   viewer.functionName(parameter_1, parameter_2 ... parameter_n)
Table 1. viewer namespace function calls
Parameter Description
viewer The name of the package that the function belongs to.
functionName The name of the function.
parameter A string representing the value of the parameter. Functions take zero or more parameters.

Calling a user-defined function in a custom namespace:

   <value compute="hr_funcs.holiday(field1.value, field2.value)"></value>

About parameters in XFDL

Parameters are variables that are passed to XFDL functions. These variables determine the result of the function. Parameter types include numbers, strings, Booleans, other functions, or references to values in a form.

In general, parameters are enclosed in single quotation marks, as shown:

   function('param1', 'param2')

Use empty quotation marks to represent null values.

In some cases you might want to copy a value from another element in the form. For example, you might want to use the value of a user-set field as the parameter in a function. This is called setting a reference. A reference is the "address" of an item, option, or argument in the form. For example, the reference to the value of a field called NameField on page 2 would be “page2.NameField.value”.

When setting a reference, the parameter should not be enclosed in single quotation marks, as shown:

   function('param1', reference)

When the reference is evaluated, the value of the referenced item is retrieved and substituted for the reference, resulting in the following:

   function('param1', 'retrieved value')

The function is then computed.

Optional parameters in viewer function calls are indicated with brackets ( [ ] ). For example:

fileOpen(startdir, [extfilter])

In the function call, the extfilter parameter is optional.

Reference strings

In some cases, your function might require a reference to the actual address of an item, instead of the value contained by the item. This is called a reference string. For example, the second parameter of the measureHeight function allows you to specify which item should be measured by providing a reference to that item.

Usually, you would provide a reference string that is enclosed in single quotation marks, as shown:

   measureHeight('pixels', 'descriptionField')

The quotation marks indicate that the function should use the reference string as the final value. So in this case, the function will measure the height of the descriptionField.

Position of characters in strings

The position of the first character in a string is at position zero. For example, the capital T in the following string is at position zero.

   This is a string