Formulas - rodekruis/EspoCRM-knowledge-base GitHub Wiki

You can find widely used formulas in EspoCRM.

Calculate age groups

Given an Integer field age and an Enum field ageGroup

if (age < 5) {
    ageGroup = "0-4";
} else if (age < 18) {
    ageGroup = "5-17";
} else if (age < 60) {
    ageGroup = "18-59";
} else {
    ageGroup = "60+";
};

Calculate age

Given an Integer field age and a Date field dateOfBirth

age = datetime\diff(datetime\today(), dateOfBirth, 'years'); Also see: datetime - EspoCRM Documentation

Set name of record

name = <fieldname>; This name will also show if there is relationships and the related record is shown in the layout.

Get information from related record

record\attribute(ENTITY_TYPE, ID, ATTRIBUTE)

For example get the date of visit for a patient record, where the Patient and Visit entities are related: $refField = record\attribute(‘Visit’, visitId, ’dateOfVisit’);

See: record - EspoCRM Documentation

⚠️ **GitHub.com Fallback** ⚠️