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
Code
var birthdate = crmForm.all.birthdate.DataValue;
if (birthdate == null)
{
crmForm.all.new_upcomingbirthday.DataValue = null;
return;
}
var today = new Date();
today.setHours(0);
today.setMinutes(0);
today.setSeconds(0);
birthdate.setFullYear(today.getFullYear());
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 demand – 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 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.
No comments:
Post a Comment