Example Birthday Fix Workflow
The following is an example CRM Workflow that shows off the power of the SonomaPartners.DateTimeUtilities. The goal of the workflow is to workaround the native Time Zone issue when storing Date fields in CRM.
If you use a Date only field such as Birthdate, CRM will store the time as midnight in the user's local time zone. The issue with this is that, for example, if a user who updates the Birthdate field is in Central time zone then a user in Mountain time zone
views the Birthdate, it will be one day earlier. This is because the Date/Time field is stored as midnight Central time which is 11 PM Mountain time the day before.
With the SonomaPartners.DateTimeUtilities, we can work around the time zone issue with a workflow using four simple steps.
1) First add a step for GetDateParts passing the Birthdate field into the custom activity.
2) Next use a Check Condition on the result of the GetDateParts custom activity. We want to check if the "Hour" is NOT set to 12. This way the Birthdate will not be updated multiple times if the Hour is already set to Noon.
3) Add a step for a successful Check Condition from step 1. This step will call SetDateParts passing in the Birthdate field and also with the "Hour" argument set to 12. This will overwrite the Midnight Date/Time field and set it to Noon.
Note: The default value of each argument is -2147483648 (the minimum value of an integer), therefore if you update the arguments, you will see each null value set to -2147483648 which is intended.
4) Lastly, add a native workflow step to Update the Contact record setting the Birthdate field to the result of the SetDateParts activity. This will set the Birthdate to Noon which gives some buffer so that users in other time zones will still see the same
Date rather than the day before or the day after.
The utilities can be helpful for having a workflow wait til a more specific Date/Time. For example, you could have a workflow execute a process at 2 AM the day after a record is created. This can be done is three simple steps as well.
- Pass the Created On into the AddDateParts with the "Day" argument set to 1. This will add 1 day to the Created On Date/Time and return the result.
- Pass the result of the AddDateParts activity into a SetDateParts activity with the "Hour" argument set to 2. This will set the Hour to 2 AM.
- Lastly, make a Wait step and set the Date/Time to the result of the AddDateParts activity (which is now set to 2 AM the day after the original Created On)