Skip to primary content
Skip to secondary content

Passion Dynamics

Microsoft Power Platform & Azure blog by Rawish Kumar

Passion Dynamics

Main menu

  • Home
  • About Me
  • Contact

Tag Archives: workflow to send email on birthday today

Send Birthday Email To Customers[ Workflow + JavaScript]

Posted on May 21, 2018 by Rawish Kumar Prajapati

In one of my recent blogs I have explained and showed you an approach to send birthday emails to your customers in dynamics CRM using a code solution in which i have used a console application, you can find it here :  Send Birthday Email To Customers [ Simplest Code Solution]

However In this blog i have come up with an approach of using Workflow + JS. So without further due, lets get into this.

Things to do:

  1. Create a Date Only field on contact entity and place it on the form, named “Custom Birthday” .
  2. Create another Date only field on contact entity and place it on the form , named “Today’s date” [you will know why i have used this later]1
  3. Add below Javascript code to your on change event of Birthday field:
    var SetBirthday = function (executionContext)
    {
     debugger;
     var actualBirthday = executionContext.getFormContext().getAttribute("birthdate");
     
     if(actualBirthday!= null)
     {
    
    var date1 = new Date(actualBirthday.getValue());
     var dd = date1.getDate();
     var mm = date1.getMonth();
     var yyyy = (new Date()).getFullYear();
    
    var customField = executionContext.getFormContext().getAttribute("new_custombirthday");
     customField.setValue(new Date(yyyy, mm, dd));
    
    
    
    
    var todayDate = new Date();
     var d = todayDate.getDate();
     var m = todayDate.getMonth();
     var y = todayDate.getFullYear();
    
    var dateField = executionContext.getFormContext().getAttribute("new_todaysdate");
     dateField.setValue(new Date(y, m, d));
    
    }
    
    }

2

What this javascript will do is as soon as someone enters the birthday of contact – it will extract the day and month part from the birthday and put in the next field with current year. So, for e.g if my birthday is entered as  05-01-1993 , it will set the custom birthday to 05-01-2018 & the next thing it doesn’t is simply put today’s date in the today’s date field.

4. Create a new entity named “Schedular” and add below field to it:
a. Deletion date (Date Only Field)
b. Contact ( lookup to contact entity)
3

 Workflow

  1. Create a workflow and name it as required on contact entity.  Run this on Create of contact and also on change of the birthday field.4
     a. First condition to check if “Today’s Date“(custom field we created) is less than “Custom birthday” field.  If this condition passed we creating a schedular record by putting the custom birthday field as deletion date.

    5
    b. Second condition to check if  “Today’s Date“(custom field we created) is greater than “Custom birthday” field.  If this condition passed we creating a schedular record by putting the custom birthday field + 12 months as deletion date.
    6
    c. third condition simply checks if Today’s date is equal to Custom birthday field – sending email right away.
    7.JPG

    It will create schedular records with required deletion date and send email right away if birthday is today or on the changed date.

    Bulk Delete Job

    1. Create a bulk delete job with condition as below to simply delete schedular records whose deletion date is today , the job should run everyday ( preferably in the morning  as as business needs)
    Go to Settings > Data Management> Bulk record deletion > Create a new job :

    8

    9.JPG

  2. Save and close the job – this will run every day on the time you will select above and delete schedular records.

    Final Workflow

    1. Create a workflow which should run on Schedular entity and run it before the deletion of schedular record ( convert it to real-time mode)

    10

    a. first condition checks if Deletion date of the schedular is equal to contact’s custom birthday date, we are sending birthday wishes. ( because birthday might have changed later and create other schedular records hence we must check if this shedular is the correct one)

    b. within first condition after sending birthday email – we have to create a another workflow schedular record with deletion date + 12 months ( for the next year ).

    11

    c.  add an otherwise condition to check if deletion date is not equal to the custom birthday of the contact. we would not send email in that condition and simply stop the workflow.

    So, the process of deletion of shedular records and creation will continue and send email to customers on their birthdays.

 

Few things:

  1. Instead of using custom today’s date i tried using Execution time of the workflow but because the birthday field is Date only but Execution time is  Date Time format. the equal to condition will never meet and always go in less then condition.
  2. You can hide “Custom birthday” & “Today’s Date” on the form.
  3. The javascript above is very specific to dynamics crm 365 v9. Can be changed for other CRM versions such as instead of using  :var actualBirthday = executionContext.getFormContext().getAttribute(“birthdate”);

    you can use :

    var actualBirthday = Xrm.Page.getAttribute(“birthdate”).getValue();

  4. The schedular option is really helpful and let you escape from waiting condition wofkflows. To read more :  Escape from waiting condition workflows – Microsoft Dynamics CRMI hope this helps!
    please leave your comments for any suggestions or doubt.

Share this:

  • Twitter
  • Facebook

Like this:

Like Loading...
Posted in Uncategorized | Tagged Author:Rawish, birthday email crm, CRM, get customers whose birthday is today, how to get customer with birthday as today, how to send birthday email CRM, how to send birthday emails using workflow, Linq query to find customers with birthday today, Microsoft Dynamics CRM, send automatic email to customer on birthday, send birthday email automatically in crm, send birthday email to customer using workflow, Send Birthday Email To Customers, Send Birthday Email To Customers programatically, Send Birthday Email To Customers programmatically, Send Birthday Email To Customers using console application, send email to contacts on birthday, send email to customer on birthday, send email to customer on their birthday, send email to customer whose birthday is today using workflow, send wishes to customer on birthday using workflow, today customer birthday, use workflow to send email to customer, use workflow to send email to customer on birthday, workflow birthday email, workflow email birthday, workflow to send email on birthday today
Follow Passion Dynamics on WordPress.com

I'm not an expert; I'm learning!

Top Posts & Pages

  • How to insert dynamic values from custom entities in an email template - Microsoft Dynamics CRM
  • Register Dynamics CRM App With Azure for OAuth 2.0 Authentication
  • White Paper - Migrate Microsoft Dynamics CRM 2016 On-Premises to CRM 365 Online v9
  • Color Subgrid in Microsoft Dynamics CRM 365
  • CREATE AUTO-NUMBER ATTRIBUTE IN DYNAMICS CRM 365 USING WEB API + Use POSTMAN with CRM Online
  • Alternate Keys
  • Audit History
  • Business Rules
  • Calculated & Rollup Fields
  • Certifications
  • CRM Code Helpers
  • CRM WebApi/Javascript
  • Data Migration
  • Deployment
  • Dynamics 365 For Marketing
  • Dynamics CRM 365 Online
  • Dynamics Portal
  • Microsoft Dynamics CRM Emails
  • Microsoft Dynamics CRM Reporting
  • Microsoft Dynamics CRM SDK
  • Microsoft Dynamics CRM Services
  • Microsoft Dynamics CRM Solutions
  • Reblogged
  • Uncategorized
  • Unified Service Desk for Dynamics CRM
  • Voice Of Customer
  1. Maheshwar on Enable Custom Entities For Marketing Segment Dynamic QueryApril 4, 2022

    Hi Rawish Kumar , thank you for explaining how to add related entities in segments. I am unable to add…

  2. Amritha on How to insert dynamic values from custom entities in an email template – Microsoft Dynamics CRMMarch 18, 2022

    Can we add attributes from custom entities into a marketing email template?

  3. George Rizza on How to insert dynamic values from custom entities in an email template – Microsoft Dynamics CRMNovember 4, 2021

    This is the best I have seen but I am still not clear on the format for the lookup value.…

  4. Michelle on Enable Custom Entities For Marketing Segment Dynamic QuerySeptember 10, 2021

    Do you need to have a Customer Insights license in order to turn this feature on?

  5. How to use JavaScript to fill parent lookup on form in Dynamics 365 CRM on-premise? - Tutorial Guruji on Get lookup value from other entity and set it on the form using Web API in Microsoft Dynamics CRM 2016April 9, 2021

    […] What you need is, a Javascript function to trigger on change of first lookup to query necessary fields from…

Create a website or blog at WordPress.com
  • Follow Following
    • Passion Dynamics
    • Join 42 other followers
    • Already have a WordPress.com account? Log in now.
    • Passion Dynamics
    • Customize
    • Follow Following
    • Sign up
    • Log in
    • Report this content
    • View site in Reader
    • Manage subscriptions
    • Collapse this bar
 

Loading Comments...
 

    %d bloggers like this: