MathVariable Element

Within the <Math> element, calculations can be evaluated using MathVariables. MathVariables are variables that are used in the Math section of business rule configuration and use the <MathVariable> tag.  A MathVariable name is assigned as the value of the attribute VARIABLENAME.  After the user names the MathVariable, they can identify what type of MathVariable to create.  There are various types of MathVariables available to configure processing.  MathVariables can be used to retrieve a field value, create arrays, structure if-then structures, perform calculations with operators, or call functions.  Each of the math types has its own set of attributes, elements, and possible values, which are listed below.  All MathVariables must have a data type declared using the DATATYPE attribute.

The <MathVariable> tag can use a LOG="Yes" attribute, which will log results to AsActivityMath. When using logging, remember that the system performs all logging at the end of transaction processing. Therefore, only the ending value of a MathVariable is logged. Although the configuration allows the LOG attribute on any use of a variable in the configuration, the intermediate values are not logged, even if LOG="Yes" occurs multiple times for the same variable. In such a case, to avoid confusion it is best to specify the LOG attribute only for the last use of the variable. Another method is to create a "Log Section" at the bottom of the configuration that specifies all math variables to be logged.

There are also <MathLoop> and <MathIF> elements, which are available to perform loops and if conditions, respectively. 
Both must have a data type declared as well.

Available DATATYPE Options

  1. ACTIVITY
  2. BIGTEXT
  3. BOOLEAN
  4. CURRENCY
  5. DATE
  6. DECIMAL
  7. INTEGER
  8. TEXT
  9. MAP
  10. OBJECT
  11. XML (Works with TYPE=”VALUE” and “FIELD”)

Important: DATATYPE of either decimal or integer may not be blank and a DEFAULT attribute must be defined. If the use is dealing with integers that are larger than 2147483648 in math configuration then the DECIMAL data type must be used.

MathVariables may be used to pass values into spawn configuration.  Math statements are processed sequentially from top to bottom in the configuration.

 MathVariable TYPE Attribute
Element/Tag Attribute Definition Element/Attribute Value and Description

<MathVariable>

TYPE

 

FIELD: Element Values

• [Entity]:[MathVariable]:EffectiveDate

• [Entity]:[MathVariable]::MoneyType

• [Entity]:[MathVariable]:TypeCode

These configurations above allows access to the table column values for the GUID referenced in MathVariable.

• [Entity]:[MathVariable]: Balance

This configuration calculates total amount left at Financial Entry level for the GUID referenced in the MathVariable.

• [Entity]: Balance

This configuration calculates the total Balance Amount left at Policy level.

CLEARVALUE

Value: Yes / No

Default Value: No

Optional Element:

Yes: The value of the math variable will be deleted after the execution of all the Attached Rules at the end of activity processing and will not be visible on the Math tab in the Activity details screen.

No: The value of the math variable will be retained after activity processing and will be displayed in the Math tab in the Activity details screen.

XML Example

<MathVariables>
<!-- Calculate Days from Last Bank Draft -->
<MathVariable VARIABLENAME="LastActiveBankDraftEffectiveDate" TYPE="VALUE" 
DATATYPE="DATE"></MathVariable>
<MathVariable VARIABLENAME="BankDraftEndDate" TYPE="FIELD" 
DATATYPE="DATE">Activity:EffectiveDate</MathVariable>
<MathVariable VARIABLENAME="LastActiveBankDraftEffectiveDate" TYPE="SQL" DATATYPE="DATE">
<SqlServer>SELECT TOP 1 AsActivity.EffectiveDate FROM AsActivity 
JOIN AsTransaction ON AsTransaction.TransactionGUID = AsActivity.TransactionGUID 
AND AsTransaction.TransactionName = 'BankDraft' 
WHERE AsActivity.PolicyGUID = '[Policy:PolicyGUID]' 
AND AsActivity.StatusCode IN ('01','13','14') 
AND AsActivity.TypeCode IN ('01','04') 
ORDER BY AsActivity.EffectiveDate DESC
</SqlServer>
<Oracle>SELECT EffectiveDate FROM (SELECT AsActivity.EffectiveDate FROM AsActivity 
JOIN AsTransaction ON AsTransaction.TransactionGUID = AsActivity.TransactionGUID 
AND AsTransaction.TransactionName = 'BankDraft' 
WHERE AsActivity.PolicyGUID = '[Policy:PolicyGUID]' 
AND AsActivity.StatusCode IN ('01','13','14') 
AND AsActivity.TypeCode IN ('01','04') 
ORDER BY AsActivity.EffectiveDate DESC) WHERE ROWNUM = 1
</Oracle>
<DB2>SELECT AsActivity.EffectiveDate FROM AsActivity 
JOIN AsTransaction ON AsTransaction.TransactionGUID = AsActivity.TransactionGUID 
AND AsTransaction.TransactionName = 'BankDraft' 
WHERE AsActivity.PolicyGUID = '[Policy:PolicyGUID]' 
AND AsActivity.StatusCode IN ( '01' , '13' , '14' ) 
AND AsActivity.TypeCode IN ( '01' , '04' ) 
ORDER BY AsActivity.EffectiveDate DESC FETCH FIRST 1 ROWS ONLY
</DB2>
</MathVariable>
<MathVariable VARIABLENAME="TestLastActiveBankDraft" TYPE="FUNCTION" 
DATATYPE="BOOLEAN">IsEmpty(LastActiveBankDraftEffectiveDate)</MathVariable>
<MathIF IF="TestLastActiveBankDraft = false">
<MathVariable VARIABLENAME="DaysFromLastBankDraft" TYPE="FUNCTION" 
DATATYPE="INTEGER">DaysDiffOf(LastActiveBankDraftEffectiveDate,BankDraftEndDate)</MathVariable>
</MathIF>
<MathVariable VARIABLENAME="CommentToSpawn" TYPE="FIELD" 
DATATYPE="BIGTEXT">Activity:AnnualStatementComment</MathVariable>
<MathVariable VARIABLENAME="XmlValueMV" TYPE="VALUE" DATATYPE="XML"/>
<MathVariable VARIABLENAME="XmlFieldlMV" TYPE="FIELD" DATATYPE="XML">Activity:XMLData</MathVariable>
<MathVariable VARIABLENAME="CorrectionDateMV" TYPE="MULTIFIELD" INDEX="1" DATATYPE="DATE">CorrectionDate</MathVariable>
   <MathVariable VARIABLENAME="[MathVariable]" TYPE="FIELD" DATATYPE="XXX">Entity:[MathVariable]:[ColumnName]</MathVariable>
   <MathVariable VARIABLENAME="[MathVariable]" TYPE="FIELD" DATATYPE="DECIMAL">Entity: Balance</MathVariable>
<MathVariable VARIABLENAME="PolicyNotify" TYPE="PROCESS" NAMESPACE="com.oi.osc" OBJECT="MathPlugin" DATATYPE="OBJECT">
</MathVariables>

Object

The MathVariable of type OBJECT can be used to update all the dynamic and non-system fixed fields.

MathVariable Object Type Attributes
TYPE=Object
Element Attribute Definition Element/Attribute Value and Description
<MathVariable>      
TYPE  

Value: OBJECT

Note: It is not necessary that the OBJECT attribute is used within an OBJECTLOOP when the Object name is 'COMMDETAIL'

OBJECTNAME  

Value: AsCodeCreateObjectType

It is used to identify the object name.

MathVariable/Static/ActivityField. (Currently available value is "COMMDETAIL")

SOURCEARRAY   Note: It is not required when the object name is COMMDETAIL.
OPERATION  

Value: CREATE

It is used to create a OBJECT type of MathVariable. This is currently supported only for OBJECTNAME='COMMDETAIL'.

Please note that, in case of using a loop to set the OBJECT, then the OBJECT creation needs to be within the Loop and not outside the Loop.

   

Value: SETVALUE

It is used to specify the operation as setting value to the Fields of the OBJECT.

OBJECTNAME is not required for this operation.

The MathVariable name should be same as the MathVariable of type OBJECT for which the fields are being set.

DATATYPE  

This should be set to OBJECT when the operation is CREATE.

For OPERATION = SETVALUE the data type will be the data type of the field that is being assigned the value.

FIELDNAME   This is field of the OBJECT for which the value is being set using SETVALUE operation.This is valid only with SETVALUE operation.
SOURCE  

Value: MEMORY / DATABASE

Optional, indicates where the SegmentField value should be retrieved from default is DATABASE used when MV TYPE="SEGMENTFIELD" SEGMENTGUID="xxx".

If the MEMORY is configured and nothing is in MEMORY, then searches for the value in DATABASE. When a value does not exist in DATABASE then it returns null value and it will not error.

Note: The SOURCE attribute is only applicable when MathVariable Type is "SEGMENTFIELD" and "SEGMENTGUID" is used.

CLEARVALUE

Value: Yes / No

Default Value: No

Optional Element:

Yes: The value of the math variable will be deleted after the execution of all the Attached Rules at the end of activity processing and will not be visible on the Math tab in the Activity details screen.

No: The value of the math variable will be retained after activity processing and will be displayed in the Math tab in the Activity details screen.

XML Schema

Transaction Math to retrieve data from MEMORY / DATBASE

<MathVariable VARIABLENAME="Smoke" TYPE="SEGMENTFIELD" SEGMENTGUID="SegmentGuidOfBase" SOURCE="MEMORY" DATATYPE="TEXT">SegmentTobaccoPremBasis</MathVariable>

 

Object Array

A Transaction Math of type "OBJECTARRAY" rule can be used to hold an array of objects. The array supports three operations:

  • CREATE - Creates an OBJECTARRAY
  • APPEND - Appends to an existing ARRAY with an OBJECT
  • INSERT - Inserts into an existing array at a specified INDEX
  • INDEX - Specifies the index during the INSERT operation and it is ignored if used with other operations. MathVariable and static numbers are allowed for this operation.
MathVariable ObjectArray Type Attributes
TYPE=ObjectArray
Element Attribute Definition Element/Attribute Value and Description
<MathVariable>    

 

TYPE  

Value: OBJECTARRAY

Contains an array of OBJECTS

OPERATION  

Value: CREATE

It is a variable whose value is the length of a newly created array. A new array with the length equal to the element value.

When CREATE operation is used, the value of the MathVariable cannot be blank and must be an integer (or a MathVariable containing an integer).

This value allows the system to predetermine the size of the array to build and reserve memory for it.

Note: This value should be instantiated as zero (0) if the size of the array is not yet known.

   

Value: APPEND

A variable of type OBJECT(all objects of an array should be of the same kind) whose value is appended to array SOURCEARRAY.

Results in new array equal to array indicated by SOURCEARRAY attribute with an additional OBJECT appended.

Note: If the SOURCEARRAY attribute is specified, the name must be the same as the name of the specified VARIABLENAME. The append operation will insert the math object at the end of the array.

   

Value: INSERT

A variable of type OBJECT whose value is placed in the array at a specific location/index.

The object is inserted into the array using insert operation. If the specified index does not exist (e.g. the array is too short), it will throw an error "Array Index Out of Bounds".

   

Value: LENGTH

Returns the LENGTH of the OBJECT array specified in the SOURCEARRAY attribute.

SOURCEARRAY   It is the MathVariable name of the source array. This is used when the operation is APPEND/INSERT/LENGTH.
INDEX   It is used to specify the INDEX when the OPERATION is INSERT.
DATATYPE  

Value: OBJECT

It specifies the data type.

CLEARVALUE

Value: Yes / No

Default Value: No

Optional Element:

Yes: The value of the math variable will be deleted after the execution of all the Attached Rules at the end of activity processing and will not be visible on the Math tab in the Activity details screen.

No: The value of the math variable will be retained after activity processing and will be displayed in the Math tab in the Activity details screen.

XML Schema

Transaction Math to Create Object Array and Commission Object

<MathVariable VARIABLENAME="CurrencyTextMV" TYPE="VALUE" DATATYPE="TEXT">INR</MathVariable>

<!-- Comment AggregateCommissionCurrencyMV is a Money field defined in CommissionDetailScreen BR -->

<MathVariable VARIABLENAME="AggregateCommissionCurrencyMV" TYPE="FUNCTION" DATATYPE="CURRENCY">ToCurrency(AggregateCommissionAmountMV,CurrencyTextMV)</MathVariable>
<MathVariable VARIABLENAME="CommissionObjectArrayMV" TYPE="OBJECTARRAY" OPERATION="CREATE" DATATYPE="OBJECT">0</MathVariable>
<MathVariable VARIABLENAME="CommissionObject" TYPE="OBJECT" OBJECTNAME="CommissionDetailMV" OPERATION="CREATE" DATATYPE="OBJECT"></MathVariable>
<MathVariable VARIABLENAME="CommissionObject" TYPE="OBJECT" OPERATION="SETVALUE" FIELDNAME="EffectiveDate" DATATYPE="DATE">SystemDateMV</MathVariable>
<MathVariable VARIABLENAME="CommissionObject" TYPE="OBJECT" OPERATION="SETVALUE" FIELDNAME="TypeCode" DATATYPE="TEXT">COmmissionTypeCodeMV</MathVariable>
<MathVariable VARIABLENAME="CommissionObject" TYPE="OBJECT" OPERATION="SETVALUE" FIELDNAME="EntityType" DATATYPE="TEXT">POLICY</MathVariable>
<MathVariable VARIABLENAME="CommissionObject" TYPE="OBJECT" OPERATION="SETVALUE" FIELDNAME="EntityGUID" DATATYPE="TEXT">Policy:PolicyGUID</MathVariable>
<MathVariable VARIABLENAME="CommissionObject" TYPE="OBJECT" OPERATION="SETVALUE" FIELDNAME="SourceComponentTypeCode" DATATYPE="TEXT">BASEPRM</MathVariable>
<MathVariable VARIABLENAME="CommissionObject" TYPE="OBJECT" OPERATION="SETVALUE" FIELDNAME="Amount" DATATYPE="DECIMAL">CommissionAmountUSDMV</MathVariable>

<!-- Comment Please note that the amount and currency for the fixed fields under AsCommissionDetails table is set separately while the dynamic field AggregateCommission" uses a datatype of Currency -->

<MathVariable VARIABLENAME="CommissionObject" TYPE="OBJECT" OPERATION="SETVALUE" FIELDNAME="CurrencyCode" DATATYPE="TEXT">CurrencyCodeMV</MathVariable>
<MathVariable VARIABLENAME="CommissionObject" TYPE="OBJECT" OPERATION="SETVALUE" FIELDNAME="StatusCode" DATATYPE="TEXT">StatusMV</MathVariable>
<MathVariable VARIABLENAME="CommissionObject" TYPE="OBJECT" OPERATION="SETVALUE" FIELDNAME="ClientGUID" DATATYPE="TEXT">ClientGUIDMV</MathVariable>
<MathVariable VARIABLENAME="CommissionObject" TYPE="OBJECT" OPERATION="SETVALUE" FIELDNAME="AggregateCommission" DATATYPE="CURRENCY">AggregateCommissionCurrencyMV</MathVariable>
<MathVariable VARIABLENAME="CommissionObjectArrayMV" TYPE="OBJECTARRAY" OPERATION="APPEND" SOURCEARRAY="CommissionObjectArray" DATATYPE="OBJECT">CommissionObject</MathVariable>

Date Format

The MathVariable returns a date format string as specified in TOFORMAT.

  • If MathVariable TYPE=DATE and DATATYPE= FORMATDATE, OPRERATION=GENERATE, will return the system Date/timestamp in a format specified in TOFORMAT
  • If MathVariable TYPE=DATE and DATATYPE= FORMATDATE, OPRERATION= CONVERT, will convert the defined time into a format specified in TOFORMAT
Example of Date format Conversion in a Transaction

For example, it can be used in PushNotifications when EVENTDATETIME is found in parameter.

Define two math variables in the transaction xml, one to generate time format and the other for date format conversion.
The EVENTDATETIME is printed in the same format if configured in PushNotifications.

<MathVariable VARIABLENAME="EventDateTime" TYPE="DATE" DATATYPE="FORMATDATE" OPERATION="GENERATE" TOFORMAT="yyyy-MM-dd HH:mm:ss.SZ"></MathVariable>
<MathVariable VARIABLENAME="ActivityEffectiveDate" TYPE="DATE" DATATYPE="FORMATDATE" OPERATION="CONVERT" TOFORMAT="yyyy-MM-dd HH:mm:ss.SZ">Activity:EffectiveDate</MathVariable>
<MathVariable VARIABLENAME="AddressEffectiveDate" TYPE="FIELD" DATATYPE="DATE" CLEARVALUE="Yes">Activity:EffectiveDate</MathVariable>
Date format Conversion in a Transaction
TYPE=DATE
Element Attribute Definition Element/Attribute Value and Description
<MathVariable>      
TYPE  

Values: DATE

OPERATION  

Values: GENERATE, CONVERT

DATATYPE   Values: FORMATDATE

CLEARVALUE

Value: Yes / No

Default Value: No

Optional Element:

Yes: The value of the math variable will be deleted after the execution of all the Attached Rules at the end of activity processing and will not be visible on the Math tab in the Activity details screen.

No: The value of the math variable will be retained after activity processing and will be displayed in the Math tab in the Activity details screen.

Transaction Math to convert a Date

<MathVariable VARIABLENAME="EffectiveDateUpdated" TYPE="DATE" DATATYPE=FORMATDATE OPERATION="CONVERT"  TOFORMAT="yyyy-mm-dd 'at' HH:mm:ss z"> Activity:EffectiveDate</Math>

The following pattern letters can be used to define the TOFORMAT or date conversion:

Transaction Math: to convert a Date
Letter Date or Time Component Presentation Example
y Year-of-era Year 200404
Y Week year Year 200909
M Month in year Month JulyJul07
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day name in week Text TuesdayTue
u year year 200404
a Am/pm marker Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
z Time zone General time zone Pacific Standard TimePSTGMT-08:00
Z Time zone RFC 822 time zone -0800
X Time zone ISO 8601 time zone -08-0800-08:00
e/c localized day-of-week number/text 2; 02; Tue; Tuesday; T

Pattern letters are usually repeated, as their number determines the exact presentation.

Within date and time pattern strings, unquoted letters from 'A' to 'Z' and from 'a' to 'z' are interpreted as pattern letters representing the components of a date or time string. Text can be quoted using single quotes (') to avoid interpretation. "''" represents a single quote. All other characters are not interpreted; they are simply copied into the output string during formatting or matched against the input string during parsing.

Examples:

Date and Time: Pattern
Date and Time Pattern Result
"yyyy.MM.dd 'at' HH:mm:ss z" 2001.07.04 at 12:08:56 PDT
"EEE, MMM d, ''yy" Wed, Jul 4, '01
"h:mm a" 12:08 PM
"hh 'o''clock' a, zzzz" 12 o'clock PM, Pacific Daylight Time
"K:mm a, z" 0:08 PM, PDT
"EEE, d MMM yyyy HH:mm:ss Z" Wed, 4 Jul 2001 12:08:56 -0700
"yyyy-MM-dd'T'HH:mm:ss.SSSZ" 2001-07-04T12:08:56.235-0700
"yyMMddHHmmssZ" 010704120856-0700
"YYYY-'W'ww-u" 2001-W27-32001