Namespace: af

af

Adaptive form API. This namespace is available to the user during scripting. The namespace provides some utility APIs that can be used in the scripts

Since:
  • 6.0

Methods


<static> sum(panels, fieldName)

sum up a set of fields inside a set of panels.

Sums up all the fields having the name fieldName in a set of panels

Note: If an element inside the panels Array is not an adaptive form Panel or field referred by fieldName in a panel is not a Numeric Field, it will not be considered.

Parameters:
Name Type Description
panels Array.<Panel>

array of Panel objects

fieldName string

name of the numericField

Since:
  • 6.0
Returns:

sum of the value of the fields

Type
number
Example

returns the sum of all fields named nf5 inside all the instances of panel p4

af.sum(p4.instanceManager.instances,'nf5')

<static> max(panels, fieldName)

find the maximum value field among a set of fields

Finds the field having the maximum value amongst the set of fields with the name fieldName in a set of panels.

Note: If an element inside the panels Array is not an adaptive form Panel or field referred by fieldName in a panel is not a Numeric Field, it will not be considered.

For the purpose of calculations null values are treated as 0

Parameters:
Name Type Description
panels Array.<Panel>

array of Panel objects

fieldName string

name of the numericField to consider

Since:
  • 6.0
Returns:

The Field having the maximum value among a set of fields

Type
Field
Example

returns the field having the maximum value among all fields that are named nf5 inside all the instances of panel p4

af.max(p4.instanceManager.instances,'nf5')

<static> min(panels, fieldName)

find the minimum value field among a set of fields

Finds the field having the minimum value amongst the set of fields with the name fieldName in a set of panels.

Note: If an element inside the panels Array is not an Adaptive Form Panel or field referred by fieldName in the panel is not a Numeric Field, it will not be considered.

For the purpose of calculations null values are treated as 0

Parameters:
Name Type Description
panels Array.<Panel>

array of adaptive forms Panel objects

fieldName string

name of the numericField

Since:
  • 6.0
Returns:

the field having the minimum value

Type
Field
Example

returns the field having the minimum value among all fields that are named nf5 inside all the instances of panel p4

af.min(p4.instanceManager.instances,'nf5')

<static> reduce(panels, fieldName, iterator, memo [, context])

boils down a values of multiple fields into a single value.

Value of fields, having the name fieldName in the panels array, are combined into a single value as per the iterator function.

memo is the initial state of the reduction, and at each successive step it should be returned by iterator.

A list of Fields is identied by looking for Field having the name fieldName inside each Panel in the panels array. Then the iterator function is called for each of the Fields

The iterator is called as many times as the length of the fields list, and is passed three arguments:

  • memo, for first iteration it is the value passed and for successive iterations the value returned by iterator in the previous iteration.
  • Panel object, Parent Panel of the Field object
  • Field object, Field from the list of fields having the index equal to the iteration number
Parameters:
Name Type Argument Description
panels Array.<Panel>

Array containing the Panel objects

fieldName string

Name of the field to look in the panels array provided in the first argument

iterator af~ReduceIterator

function which will be called for each Field object

memo *

initial state of reduction

context object <optional>

this param in the iterator will point to this object.

Since:
  • 6.0
See:
Returns:

boiled down value by applying iterator recursively on each field

Type
*

<static> filter(panels, fieldName, predicate [, context])

Filters a list of fields based on the predicate

Looks through each Field having the name fieldName in the panels array, call predicate function on them iteratively and returns those fields for which predicate function returns true

The arguments to the predicate will be Panel object and Field object.

Parameters:
Name Type Argument Description
panels Array.<Panel>

Array containing the Panel objects

fieldName string

Name of the field to look in the array of Panel objects provided as the first argument

predicate af~filterPredicate

function to execute for each field

context object <optional>

this in the predicate function will point to this object

Since:
  • 6.0
Returns:

list of fields for which the predicate function returned true

Type
Array.<Field>

<static> formatDateToISOString(dateObject)

formats date object into ISO String i.e. in yyyy-mm-dd format.

Accepts a date object and passes back date in yyyy-mm-dd format which is accepted by adaptive forms

Parameters:
Name Type Description
dateObject Date

object

Since:
  • 6.0
Returns:

converts dateObject in YYYY-MM-DD format

Type
string
Example

To set today's date in Date Field

var today = new Date();
datefield.value = af.formatDateToISOString(today)

<static> avg(panels, fieldName)

averages up the values of multiple Numeric Fields

The API looks for all the Numeric Fields having the name fieldName inside the list of panels

The API is most useful to calculate the average of a Numeric Field inside a repeatable table row.

Note: If an element inside the panels array is not a Panel or fieldName inside the panel is not a Numeric Field, it will not be considered.

For the purpose of calculations null values are treated as 0

Parameters:
Name Type Description
panels Array.<Panel>

array of Panel objects

fieldName string

name of the numericField inside the panels array to consider for calculating the average

Since:
  • 6.0
Returns:

average of the value of the considered fields inside the panels array

Type
number
Example

returns the average of all fields named nf5 inside all the instances of panel p4

af.avg(p4.instanceManager.instances,'nf5')

Type Definitions


ReduceIterator(memo, panel, field)

iterator function for the af.reduce function

Parameters:
Name Type Description
memo *

initial value passed to the reduce function

panel Panel

Panel element

field Field

Field element

See:
  • af#reduce
Returns:

the value to be used as memo in the next iteration

Type
*

filterPredicate(panel, field)

predicate function for the af#filter function

Parameters:
Name Type Description
panel Panel

Panel element

field Field

Field element

See:
  • af#filter
Returns:

value of the predicate test.

Type
boolean