Hi Everyone,
We had a requirement to calculate age of the user every day and send birthday wishes to the user.
We achieved this using Microsoft flows with expression formulas.
1. Created two custom fields named as "Age" as whole number and "Upcoming birthday" as date time.
2. Created a flow in https://make.powerapps.com/ scheduled it for every day.
3. Initialize a variable to hold the Age of the current contact, named it as "Diff Years"
4. Initialize variable to hold upcomingbirth day in this year
5. Initialize another variable to hold upcoming birthday in next year.
7. Next click on Plus symbol to add action. Add Apply each action to process each contact record.
8. Set Age and upcoming birthday variables with below expressions.
Difference Years
Set current year birthday
We had a requirement to calculate age of the user every day and send birthday wishes to the user.
We achieved this using Microsoft flows with expression formulas.
1. Created two custom fields named as "Age" as whole number and "Upcoming birthday" as date time.
2. Created a flow in https://make.powerapps.com/ scheduled it for every day.
3. Initialize a variable to hold the Age of the current contact, named it as "Diff Years"
4. Initialize variable to hold upcomingbirth day in this year
5. Initialize another variable to hold upcoming birthday in next year.
6. Next connect to CDS and list the contact records. Provide the odata filter to query the contacts where upcoming birthday is less than or equals to today's date.
dk_upcomingbirthdate le @{utcNow('yyyy-MM-dd')}
7. Next click on Plus symbol to add action. Add Apply each action to process each contact record.
8. Set Age and upcoming birthday variables with below expressions.
Difference Years
sub(int(utcNow('yyyy')),int(formatDateTime(items('Apply_to_each')?['birthdate'],'yyyy')))
Set current year birthday
concat(utcNow('yyyy'),'-',formatDateTime(items('Apply_to_each')?['birthdate'],'MM'),'-',formatDateTime(items('Apply_to_each')?['birthdate'],'dd'))
Set future year birthday
concat(add(int(utcNow('yyyy')), 1),'-',formatDateTime(items('Apply_to_each')?['birthdate'],'MM'),'-',formatDateTime(items('Apply_to_each')?['birthdate'],'dd'))
9. Next update the contact record. Set the Age and Upcoming birthday fields with below expressions
Age expression
if(or(less(int(utcNow('MM')), int(formatDateTime(items('Apply_to_each')?['birthdate'],'MM'))),
and(equals(int(utcNow('MM')), int(formatDateTime(items('Apply_to_each')?['birthdate'],'MM'))),
less(int(utcNow('dd')), int(formatDateTime(items('Apply_to_each')?['birthdate'],'dd'))))),sub(variables('Years'),1),variables('Years'))
Upcoming birthday expression
if(less(int(utcNow('MM')),int(formatDateTime(items('Apply_to_each')?['birthdate'],'MM'))),
formatDateTime(variables('setDate'),'yyyy-MM-dd'),formatDateTime(variables('futurebirthday'),'yyyy-MM-dd'))
No comments:
Post a Comment