Custom functions in expressions
Custom functions can also be referenced by expressions defined in an IEG script. By
default, the setFullNameAge
and isNotNull
functions are included
in the application.
As custom functions are on the server side, they cannot be referenced by expressions that are evaluated on the client side. This means that custom functions cannot be referenced by expressions of dynamically conditional clusters. Custom functions cannot accept a variable number of parameters.
setFullNameAge
The setFullNameAge
custom function sets a Person’s fullNameAge attribute, it
concatenates the person’s firstName
and lastName
attributes and
the calculation of the age based on the dateOfBirth
attribute.
CustomFunctionMetaData.xml
<CustomFunctions>
<CustomFunctor name="CustomFunctionsetFullNameAge">
<parameters />
<returns>curam.util.rules.functor.Adaptor$BooleanAdaptor</returns>
</CustomFunctor>
</CustomFunctions>
You must update the Person schema definition and call the function in the script definition.
Example of an updated Person schema definition:
<xsd:element name="Person">
<xsd:complexType>
<xsd:attribute name="firstName" type="IEG_STRING" default=""/>
<xsd:attribute name="lastName" type="IEG_STRING" default=""/>
<xsd:attribute name="dateOfBirth" type="IEG_DATE"/>
<xsd:attribute name="fullNameAge" type="IEG_STRING" />
…
</xsd:complexType>
</xsd:element>
Example of calling the function in the script definition:
<callout id="setFullNameAgeCallout" expression="setFullNameAge()"/>
The fullNameAge
attribute is very useful when it is set for the first column of
the list element, as it enables singling out persons very easily. As it is the first column of the
list, it is used to generate the `add-link` options. The following code snippet shows you how to set
the attribute.
<list entity="Person" show-icons="false">
<title id="EmploymentIncome.Title">Employment Income</title>
<edit-link start-page="EmploymentIncomePage"/>
<delete-link/>
<add-link start-page="EmploymentIncomePage" skip-to-summary="true">
<title id="AddIncome.Title">Add income</title>
</add-link>
<column id="fullNameAge">
<title id="Person.Title">PERSON</title>
</column>
…
</list>
isNotNull
Refer to the following example for the isNotNull
function.
<loop loop-type="for-each" entity="Person"
criteria="isNotNull(Person.hasIncome) and hasIncome==true)">