All product information in wiki.bizagi.com is only valid for Bizagi BPM Suite 9.1.X.
For newer Bizagi BPM Suite versions (10.X and up) please visit the User Guide.
 

Calculate Age

From Business Process Management, BPM and Workflow Automation Wiki | BizAgi BPMS

Jump to: navigation, search

<keywords content="keywords">find age, subtract years, year, date operations</keywords>

How to Calculate Age (applies for .NET Editions)

This document explains how to calculate age in a process. In this example the user inputs the date of birth in an activity of the process whilst making a request. In the approval that follows the applicants age needs to be shown, automatically, in order to make some policy verification before the process continues.


The procedure is as follows :


1. Create a rule as in steps 1 and 2 in Compare Dates of Make Date-Time Operations in Business Rules

2. Right click on Image:HowToSendANotification_Image011.jpg and then click on Variable Declaration


3. Add the 4 variables as shown below. Bear in mind that the initial value for the first variable dtBirthDay will depend on where the date of birth is found in the data model.


In this example the data model is as follows showing how the initial value for the first variable is determined.


4. Right click on the black arrow, as shown below, and then click on Add Expression.


Choose a meaningful name for the expression, in this case Calculate Age.


Now double click on the expression just created.


Enter the following expression in the dialog box. The objective of this expression is to separate into 3 different fields (year, month, day) each of the variables declared at the beginning of the rule. Then assign the year of both dates to the variables YearT (Year of Today's Date) and YearB, so that they can be managed as numbers to perform operations.


5. Now add an IF condition by right clicking on the black arrow out of the expression created in the previous step and click on Add If.


Double click on the blank rounded rectangle on the left, as seen in the example.

Include the following condition, to ensure that today's year is greater than the year on the birth date entered by the requestor. On the right hand drop down list select Select Field.


Then click on the variable created at the beginning, which now contains the year of the birth date.


6. Add an expression by clicking on the black arrow below the condition just created and select Add Expression.


Give a meaningful name to the expression, in this case Set number of years.


Double click on the expression just created.


In the expression find the attribute where the calculated age is going to be saved. This will vary according to each data model. For this example, it is as follows:


After including the attribute, make it equal to the subtraction of the years. Use Options to avoid errors when entering the variables names.

Finally, click on OK on the expression and then on the Rule to save and close it.


7. Add the rule, that was just created, to the process by right clicking on the activity where the rule is to be executed. Then go to the Actions tab and select the rule. Select when the action is required. In the example, On Enter as it will be executed on the Approval activity, where all the required information for the rule is available.


8. Click OK and test the rule.

This is how the screen will look where the requester inputs the date of birth.


Click Next. The approvers screen will show the following information, including the age that was just calculated in the rule.


Related Topics

How to Compare Dates

How to Subtract Dates

How to Assign Today's Date

How to Add Dates


Go back to the Date-Time Operations Menu <comments />