Attribute – Expression with Array processing
The split is not focused on returned value but presents the examples of array type processing. Such approach will be used in scenarios you would like to extract the value not from the single related object form, but rather you have to process the collection of the related records in order to extract the value, which meets your original requirement.
Value for the salary from employee Employment & Compensation records
The example with showing the current employee salary on the ‘variation of contract’ document where the employee was pointed in lookup attribute (Post Holder). The salary information is stored in employment and compensation records which are available in employee card under button ‘Employment & Compensation’.
-267d1867063a23be716feedb4e1fd32e.png)
It is deployed as Number type attribute ‘Salary’ with the use of the following expression:
const compensations = ${compensationCollection};
let payRate = 0;
let latestEffectiveDate='0000-00-00';
const employeeId = '${employeeId.id}';
for (const compensation of compensations) {
if (compensation.effectiveDate > latestEffectiveDate && compensation.employee && compensation.employee.id === employeeId) {
payRate = compensation.payRate;
latestEffectiveDate = compensation.effectiveDate;
}
}
return payRate;
While defining the above expression, the required prerequisite is to create on ‘variation of contract document’ form, the 'relation view' attribute which will be showing the employment and compensation records related with the employee appointed in lookup attribute on ‘variation of contract document’ form. The ‘Relation view’ control attribute is implemented on ‘variation of contract document’ form, with the key compensationCollection . This is the screenshot from the definition of it’s Lookup and filtering section:
-aeee130ae15c1dd770baa3419916e741.png)
In order to show the records related with the appointed on ‘variation of contract’ form employee, it searches for equality of the appointed on the variation form employee (in Select attribute, which is described with employeeId key; in above definition relation view specifies it as ‘Relation own key’) with employee key on Employment and compensation form.
With:
let payRate = 0;
let latestEffectiveDate='0000-00-00';
const employeeId = '${employeeId.id}';
there are set initial values for variables. employeeId gets the id text value of the employee appointed in Select attribute (with key employeeId).
By:
if (compensation.effectiveDate > latestEffectiveDate && compensation.employee && compensation.employee.id === employeeId) {
}
system compares with logical AND whether the effective date extracted from current employment and compensation record is greater then initial value of effective date AND employee is assigned to the compensation record AND the current employment and compensation record is equal to variable which holds the currently selected on variation of contract form employee.
In the case condition is met (we want to take salary from the latest employment and compensation record with the greatest effective day from the records related with certain employee), then system updates the payRate variable with the value extracted from the record and updates variable latestEffectiveDate for next iteration:
payRate= compensation.payRate;
latestEffectiveDate = compensation.effectiveDate;
After the iterations are finished system returns the final value of the current salary:
return payRate;
Please see other examples with 'array processing' in: Multi select type