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

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.