Convert a birthdate to age in Workflow


Userlevel 2
Badge +9

Hello, I am having a little trouble trying to figure this one out.  I have a site workflow that I need to cycle through all list items (in a particular list) and capture a few things.  I'm using the Query list control to capture the information I need.  Inside the list will be birthdays.  My goal is to be able to identify any person who has just turned 23.  So, what workflow control will allow me to create an age variable from a birthdate?  Once I identify someone, send an email to the corresponding person who needs to know the information.  I can easily convert age in the form, but unfortunately that doesn't help me here.  Someone would need to jump into the forms and update them from time to time.  If someone has a way to do this, please let me know. Thanks

@sporcincula 


7 replies

Userlevel 7
Badge +17

What SharePoint version are you on as Inline functions differ if Online?

Userlevel 5
Badge +14

use calculate date action to calculate a date 23 years ago. store the result as an ISO string

 

1335i9D7C4D3055610CB4.jpg

 

 

then use query list action to find all the items where birthday equals to calculated date.

 

note this assumes the workflow will be schedule to run daily. if you will run it with different period, eg. weekly, you have to consider that - you would need then look for birtdays falling in a period of a week. so you will have to calculate two dates like -23years and -23years_and_one_week, and make the query with greater/less then conditions.

Userlevel 2
Badge +9

This works perfectly.  Slight adjustment, I had already collected the information earlier in the query list tool and setup a For Each loop to cycle through the list.  After I performed the Calculate Date, I ran a Run If, to see if the dates matched.  To answer your question, yes this workflow will be designed to run daily.  Now, I've discovered a slight problem.  There maybe several documents per person.  If I send an email each time I hit the same person's documents, the receiver of the emails may get overloaded with notices.  I need to figure out that once a person's has been identified as 23, ignore any subsequent documents.  

Userlevel 5
Badge +14

design it the opposite way, as I suggeted. it will be much more efficient - you will need to deal within workflow with just small(er) subset of items, not the whole list.

 

and it will make it easier to deal with your problem - once you read in just list of user that are to be notified for their birthday on a given date, (I guess) you do not need them to be related to source items anymore. so you can simply dense collection of user to unique user list with 'remove duplicates' operation of collection action.

then simply run for each over collection and send out single mail per user.

Userlevel 2
Badge +9

Again you saved me. I was orginally thinking of this overtly complicated double loop to perform this task.  Your process was much easier.  Here is how I have it setup now.  I start with a Calculate Date

1342i53E112A031B314D6.jpg

Using your suggestion from above.  I then query the list to pull in information I'm going to need. The variables I've setup are all collection variables.

 

1343i2F49E0FCFAA5E9D0.jpg

I then use a Collection opearation to remove duplicates.

1344i957D98CC2084EF97.jpg

Now I run a For Each loop to cycle through my unduplicated list of people.

1345iC2F7FD5DC2548CAE.jpg

1346i1C0BEB3DEDD4CADB.jpg

The index variable is a number variable.

The  collection operation now captures the person's birthday and assigns that to a different variable so I can check to see if the person turned 23.

1347iD1F63382F54588F1.jpg

The other collection operation looks to see which building the person is located.

Last step is a Run if to see if my check date is equal to the person's birth date.  If it matches, send an email.

  1348i9651800C3FE9C5A1.jpg

1349i309C17B5CA78F610.jpg

Thank you @emha for your assistance here.  I have a few other things I'll need this workflow do, but this was the section I was getting stumped on.  

 

Userlevel 5
Badge +14

great you came to a solution.

 

few notes, though ...

 

since you iterate over a collection where you removed duplicates from, you can not use its loop driving index variable to pick values from other collections. collections do not match anymore.

imagine you'd get returned collection of users like

userA

userA

userB

 

and collection of respective returned item IDs like

1

2

3

 

if you remove duplicates from user collection, you will get collection like

userA

userB

 

so if you're currently on 2nd iteration (userB) and picked a collection element from IDs at index position 2, you get completelly unrelated value.

 

 

 

since the query list action returns ONLY items that match the birthday date, you need not to check it once again with a run if action :)

Userlevel 2
Badge +9

Yes, I see what you mean.  I initially did not notice the filter you can use within the Query list.  I've implemented this change, and it works as well.  No need now for the Run if statement.  Thank you again @emha .

Reply