findMaxDateIn2SForm( )
Find the maximum value of the given date, date-time, or partial-date items in all of the repeating instances of a two-section form. This function is only applicable to date fields.
Note:
This is an aggregation function. The rule is run for each repeating section instance in the case where the target is on a two-section form.
Syntax
findMaxDateIn2SForm('variable', DateMask)
Parameters
- variable
-
Rule variables, with reference the path:
eventId.formId.itemId
.Note:
It is allowed to reuse variables passed into this function elsewhere in the rule expression, however you must add the variable as a parameter using single quotes. - DateMask
-
Optional. Date mask to use for substitution for partial dates. If not provided, partial dates are excluded from the calculation.
Note:
Use mask only for date elements and do not use it for time elements. Any missing value in the time part is considered as 00.
Return value
- Maximum date value in String format. For example,
'27-Jan-2021 00:00'
. null
if maximum is not found.
Usage tips
- Use
'DD-MON'
format as DateMask to substitute unknown (UNK
) values in the partial date values. For example, if the mask is'01-MAR'
:Partial date value Masked date Notes 'UNK-FEB-2020'
'01-FEB-2020'
Made effective for calculation using the day part of the mask. 'UNK-UNK-2020'
'01-MAR-2020'
Made effective for calculation using both, the day and month parts of the mask. - To convert return value to JavaScript date object, extra formatting should be
done. For
example:
vExample = '10-Jul-2022 10:UNK:UNK' new Date(vExample.replace(/UNK/g, "00"))
Example 3-66 Get the maximum date value for an item across a set of repeating section instances on a two-section form
// Get the maximum date value for an item across a set of repeating section instances on a two-section form
return findMaxDateIn2SForm('aeDate');
// Same as above, using a partial date field aeDate (UNK-MMM-YYYY)
return findMaxDateIn2SForm('aeDate', '01-JAN');
//to compare with another date
var maxd= findMaxDateIn2SForm('a');
var today = new Date();
var maxdate = new Date(maxd);
if(dateDiffInDays(today,maxdate)>0){
return "today>max";
}
return "today<max";
Parent topic: Two-section form functions