Part 1: Happy Birthday via Workflow using Client-Side Scripting

If you are like me, then you probably enjoy being wished a happy birthday. The birthday congratulations usually take the form of an e-mail or a phone call. If the business tries to does this for every customer, it can become unmanageable. Enter Workflow. Let’s create a Workflow that sends an e-mail to every contact on their birthday (each year).

Before looking at a potential solution, let’s take a closer at the problem we are trying to solve. If we had a contact with a birthday of April 2nd, 1983, how can I use the Workflow feature to determine when the birthday occurs this year, since each person’s age is different? This means the number of years to be added to their birthday is different. To solve this issue, let’s create a custom attribute that will track the date of this year’s birthday. Each year the attribute will be incremented by a year, so that the contact receives an e-mail each year.

NOTE: There are more generic methods of solving the problem without creating a custom attribute; however, I found that creating a custom attribute reduces the risk of e-mails not being sent out at the appropriate time.

Step #1: Create the Attribute

Create a custom datetime attribute called Upcoming Birthday (schema name should be new_upcomingbirthday). The attribute should have Date Only format.

How do I do it?

1. Open the Entity form for the Contact entity (click Settings, Customization, Customize Entities, and select Contact from the grid).

2. Create a new attribute (from the Attributes grid).

3. Set these properties and Save and Close the form:

Display Name: Upcoming Birthday
Name: new_upcomingbirthday
Type: datetime
Format: Date Only

4. Publish the customizations to the Contact entity (under Actions menu, select Publish)

Step #2: Updating the Attribute

Two approaches can be used:

1. Client-Side Scripting – Update the attribute based on changes to the birthday field.

Pros: Quick, simple, very little coding required, no .NET assembly needs to be registered.
Cons: Attribute needs to be visible on the form, relies on JavaScript

2. Custom Workflow Activity – Update the attribute using a .NET assembly

Pros: Attribute is not visible on the form, no possibility of JavaScript issues
Cons: Requires .NET assembly be registered (requires Deployment Manager privileges)

I will be discussing the first option in this blog post. The second option will be discussed in a future blog posting.

Option #1: Client-Side Scripting

1. Add the new Upcoming Birthday field to the form

2. Add the code (shown below) to the onChange event for the Birthday field (be sure to enable the event)

3. Add Upcoming Birthday for the dependencies for the event


var birthdate = crmForm.all.birthdate.DataValue;

if (birthdate == null)


crmForm.all.new_upcomingbirthday.DataValue = null;



var today = new Date();





crmForm.all.new_upcomingbirthday.DataValue = birthdate;

How do I do that?

1. Open the Entity form for the Contact entity (click Settings, Customization, Customize Entities, and select Contact from the grid).

2. Open the Form (click Forms and Views and select Form from the grid) and select the Details tab

3. Add Upcoming Birthday to the Personal Information section

4. Change the Properties of the Birthday field (select the field and click Change Properties)

5. Select the onChange event, on the Events tab, and click Edit.

6. Check the Event is enabled checkbox and copy and paste the code (shown above) into the text box.

7. Select the Dependencies tab and add Upcoming Birthday to the list of Dependent fields
Dependencies ensure that fields required by events are not removed from the form – in this case, Upcoming Birthday.

8. Save the changes

9. Publish the customizations to the Contact entity (under Actions menu, select Publish).

Step #3: Send E-mail Workflow

This workflow will send the e-mail on the contact’s birthday.

1. Create a Workflow for Contact with these triggers:

- On demand
- As a child workflow
- Record is created

2. Set the scope of the Workflow as appropriate.

3. The Workflow should have the following structure:

· Wait until Contact.Upcoming Birthday is today

· Send the Contact an e-mail wishing them a happy birthday

· Increment the Contact.Upcoming Birthday by a year

· Call itself as a Child Workflow (creates a loop)

How do I do that?
Follow these steps:

1. Create a new Workflow for the Contact entity (click Settings, Workflows, and create a new Workflow). The following Workflow triggers (events or actions that will start the Workflow) should be selected:

a. On demandclip_image001[4] will appear on the Contact form and grid. This button allows the Workflow to be applied manually. If there are existing contacts that have not yet had their Upcoming Birthday set, you can apply the Workflow using this button.

b. As a child workflow – Allows the Workflow to continue to call itself on annual basis using a Start Child Workflow step.

c. Record is created – Workflow should run when the Contact is initially created.

2. Set the Scope of the Workflow to the appropriate level (does not affect the On Demand trigger).

a. User: Workflow will only trigger on records with same as owner as the Workflow.

b. Business Unit: Workflow will trigger on records owned by any user in the same Business Unit as the owner of the Workflow.

c. Parent: Child Business Units: Workflow will trigger on records owned by any user in the same Business Unit (and any child Business Units) as the owner of the Workflow.

d. Organization: Workflow will trigger on records owned by any user.

3. Add a Wait Condition step and configure the step.

a. Select Workflow from the entity list (first drop-down list).

b. Select Timeout from the attribute list (second drop-down list).

c. Select Equals from the operator list (third drop-down list).

d. Select Upcoming Birthday from the Form Assistant

e. Save the configuration

Note: Derik Stenerson has written an article that gives more detailed instructions about the Wait Condition step, and some of its other uses, called “Turning Inaction into Action”.

4. Add a Send E-mail step and configure the step.

a. Select the To field and click the attribute drop-down list in the Form Assistant.

b. Select Contact from the attribute list, click Add, and then click OK.

c. Once you have configured the rest of the Send E-mail form as needed, save the changes.

Note: If the Contact does not have an e-mail address the Workflow will fail. As an extra precaution you may want to add a Check Condition that checks if the Contact’s e-mail address has been set.

5. Add an Update Record step and configure it.

a. In the Additional Fields tab, select the Upcoming Birthday attribute.

b. In the Form Assistant, select 12 from the Months drop-down list

c. Select After from the drop-down list under Months

d. Select Upcoming Birthday from the attribute list (second drop-down list under Look for)

e. Click Add and OK

f. Save the configuration

6. If you have not done so, click the clip_image002[4] button to save the changes to the triggers.

7. Add a Start Child Workflow step. Using the Lookup control, select the current Workflow (so that Workflow is calling itself). Since I called my Workflow “Recurring Reminders – Send E-mail”, I will select that item from the list.

8. Your Workflow should look something like this:


9. Publish the Workflow. Don’t forget to run this Workflow on existing contacts.

Now new and existing contacts will receive e-mails congratulating them on their birthday.

Michael Scott

Comments (15)

  1. Joel Calhoun says:

    So workflow -> timeout is synonymous with Now?  I was looking for a way to send emails based on a custom datetime attribute on an entity and couldn’t figure it out until I read the wait condition in this post.  Thanks for the assist.

  2. Michael Scott says:

    Workflow.Timeout until Contact.Upcoming Birthday

    basically says

    Wait until Birthday.Upcoming Birthday is Now

  3. Good article, thanks for the infor on wait condition.  Will these ‘Wait Condition’ workflows stay in memory (until they are finished/canceled) and consume large amount of resources (as number of records grow).

    Is there any way to control how often workflow wait condition is checked

  4. Michael Scott says:

    Wait Condition will only check when the attribute is changed. In the waiting state, it will be persisted and won’t be consuming large amounts of resources.

  5. Shaik says:


     I created a workflow which sends the Created date for the Contact. It is sending mails with the created date as

    Date :    31/12/2007 12:58 PM (GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi

    I want to send only date and time not the time zone. How to restrict the workflow to send only date and time

  6. JJ says:

    Yes, the post dated Feb 4 raises an excellent point: how on earth do you get CRM workflow emails to JUST print the date? There seems to be no way to control this without resorting to programming.

  7. dil says:

    Hi michael

    This is a great example – actually I was just looking for something similar for my application (I want to schedule certain tasks like sending mails on a daily basis with the help of a workflow).

    Somehow it didnt work out that easily. Like in the example I call the workflow after a wait condition as a child workflow and create a loop that way. The problem is that this only works 6-7 times and then the CRM System cancels the workflow with the following message:

    "This workflow job was canceled because the workflow that started it included an infinite loop".

    So I guess there is an internal counter which monitors the amount of calls and interferes after a threshold value.

    Do you think your example would work all the way or will you encounter the same problem after a while (well probably after 6-7 years 🙂 ) . Anyway thanks in advance for any comment on that issue of mine.



  8. Graeme says:

    Thanks for this – great help. Can it be run on a ‘form load’ event rather than ‘on change’ of the Birthday field?

    The reason I ask is that for my scenario the birthday data is imported and not entered manually. The data does therefore not ‘change’.

  9. Graeme says:

    In addition to my previous note I did also try and run the workflow on existing contacts it does not update. If I enter or change a birthday then the ‘Upcoming Birthday’ does change – so that part works. I’m afraid I can’t figure where in the workflow the Birthday changes or updates the upcoming birthday

  10. karla says:

    Hi Michael,

    I’ve got all the steps down for this workflow but can’t figure out one piece…I have lots of contacts who already have birthdays on their contact record, but I’m not sure how to update the upcomingbirthday field for all of them without manually deleting their birthday and re-typing (which does work). When I run the workflow, it just stays in the ‘waiting’ status because the upcomingbirthday field has no data.

    I tried using the import tool to clear all the birthdays and then re-import them hoping CRM would see that as an update to the field and the automatically populate the upcomingbirthday field, but that didnt’ work. Any ideas?

  11. Shannon says:

    I am having the same issue as noted already…

    I have lots of contacts who already have birthdays on their contact record, but I’m not sure how to update the upcomingbirthday field for all of them without manually deleting their birthday and re-typing (which does work). When I run the workflow, it just stays in the ‘waiting’ status because the upcomingbirthday field has no data.

    Is there a resolution for this?


  12. Dustin says:

    If I am correct, this assumed entering the full date of birth, month, day and year.  No one in their right mind would give up that information unless they have a business need to do so.  Certainly not a lead.  Might this work without the year?  Month and day only?


  13. I had to make some modifications to this, but overall, pretty good.  Check it out on YouTube.

  14. Franco says:

    Still a great article Michael – Thanks!

    Dil, your workflow’s loop is to narrow and therefore CRM flags the workflow after 6 or 7 instances. If your workflow was scheduled to over a marger period of time (i.e. annually for birthdays), this issue does not affect the looping workflow.

    Dustin, Fill in any year (if you dont have this data at hand) the workflow requires the current (or next year) and therefore the actual birthyear is unimportant.

    My question: with this workflow running, someone adds a new contact record, but neglectes to add the birthdate (or upcoming birthdate). The workflow will trigger (record created)and wait until when?

    Keep it up!

    Thanks again & Regards


Skip to main content