web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

How to create birthday email messages for customers

(0) ShareShare
ReportReport
Posted on by 5

Please i need help on how to create a workflow to automatically send email messages to customers on their birthday....thanks

I have the same question (0)
  • Verified answer
    necsa Profile Picture
    3,455 on at

    Hi Bayo,

    Please take as reference following link:

    https://community.dynamics.com/crm/b/passiondynamics/posts/send-birthday-email-to-customers-workflow-javascript

  • Bayo Adetipe Profile Picture
    5 on at

    Thanks Necdet.

    i followed the steps in the link and did as it stated successfully, but upon creating a new customer record and inserting the birthday field i get the error below promptly;

    SCRIPT ERROR

    "One of the script for this record has caused an error. ReferenceError: 'Setbirthday' is undefined at eval code. (evalcode:1:1)"

    And this is the downloaded error log file below;

    ReferenceError: 'SetBirthday' is undefined

      at eval code (eval code:1:1)

      at RunHandlerInternal (crm:5555/.../ClientApiWrapper.aspx

      at RunHandlers (crm:5555/.../ClientApiWrapper.aspx

      at ExecuteHandler (crm:5555/.../ClientApiWrapper.aspx

      at Mscrm.TurboForm.Control.CustomScriptsManager.prototype.$BQ_1 (crm:5555/.../formcontrols.js

      at Mscrm.TurboForm.Control.CustomScriptsManager.prototype.executeHandler (crm:5555/.../formcontrols.js

      at Mscrm.TurboForm.Control.CustomScriptsManager.prototype.executeHandlerByDescriptor (crm:5555/.../formcontrols.js

      at Anonymous function (crm:5555/.../formcontrols.js

      at Anonymous function (crm:5555/.../global.ashx

      at Mscrm.TurboForm.Control.Data.DataAttributeBase.prototype.fireOnChange (crm:5555/.../formcontrols.js

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Could you please your web resource code to see if there is any syntax error?

    Please use below online tool to validate syntax of your javascript code.

    esprima.org/.../validate.html

    Check if Your code is same as below

    function SetBirthday(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));
    
    }
    
    }

    Also, You should select pass execution context as first parameter. 

    https://xrmdynamicscrm.wordpress.com/2020/07/10/dynamics-crm-javascript-error-cannot-read-property-getformcontext-of-undefined/

    Please mark my answer verified if i were helpful

  • Bayo Adetipe Profile Picture
    5 on at

    Hi Bipin

    Thanks for your response,

    I have validated the  Code is syntactically valid, also i selected pass execution context as first parameter now, then i get a different kind of error again below;

    SCRIPT ERROR

    TypeError: Object doesn't support property or method 'getFormContext' at SetBirthday

  • Bayo Adetipe Profile Picture
    5 on at

    By the way, am using Dynamics CRM 2016 on premise

  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    SInce you are using CRM 2016 onpremise. I would recommend to update code to use Xrm.Page instead of formcontext.

    Use below code and check if it works.

    function SetBirthday(executionContext)
    {
     debugger;
     var actualBirthday = Xrm.Page.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 = Xrm.Page.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 = Xrm.Page.getAttribute("new_todaysdate");
     dateField.setValue(new Date(y, m, d));
    
    }
    
    }

    Please mark my answer verified if i were helpful

  • Bayo Adetipe Profile Picture
    5 on at

    Thanks Bipin...this solved the issue

  • Bayo Adetipe Profile Picture
    5 on at

    Hello Bipin,

    I  made the Today's date and Custom birthday field visible on the form then created a new customer with birthday field  as todays date, but the Today's date and Custom birthday field was empty, it didn't extract to it automatically, but i entered it manually and i received the email notification. So the issue now is the Today's date and Custom birthday field was not filled automatically as supposed with the Jscript,  Kindly help. Thanks

  • Suggested answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    I did quick test with your js code. And it works as expected.

    Make sure you have added event on both onload and onchange of Birthday field.

    4721.CQ45.PNG

    Please mark my answer verified if i were helpful

  • Bayo Adetipe Profile Picture
    5 on at

    i can only see OnChange event only for Birthday field.....how do i find and add Onload event for the same birthday field...Thanks

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Pallavi Phade Profile Picture

Pallavi Phade 98

#2
Tom_Gioielli Profile Picture

Tom_Gioielli 60 Super User 2025 Season 2

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans