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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Field is a date range, how can I set a workflow to run 90 days prior?

(0) ShareShare
ReportReport
Posted on by 26

I have a field called,  "Plan Year Cycle" on the Account record.  This is a drop down field.  When the user picks Feb1-Jan 31 as an option, I need the Run Time field to show 90 days before Feb 1.  So the Run Date should show 1/1/ and then the current year or upcoming year if the date has already past, so this one would be 1/1/2020.  Then once the system hits the Run Date value a workflow needs to get kicked off and do some things, and right before it is done, it needs to update the Run Date field to still make it 1/1/ but now bring in the next year (1/1/2021).

Looking for ideas on how to accomplish something like this. Thank you in advance.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Radu Chiribelea Profile Picture
    6,667 on at

    Hello,

    I think you'd need some javascript on the form or a plug-in which sets the Run Date when the Plan Year Cycle is changed.

    This should then trigger a workflow that has a timeout condition (see community.dynamics.com/.../how-to-set-up-a-crm-workflow-timeout-condition or blog.clickdimensions.com/crm-workflows-wait-versus-timeout) or configure an SLA, so that it gets execute on the date when it should run.  

    Depending on what your workflow needs to to you can either get it done via the out of the box workflows or you'd need to develop some custom workflow activity.

    Hope this helps,

    Radu

  • Suggested answer
    Alok Singh Profile Picture
    910 on at

    Hello,

    I think you can have have 2 custom field (Run Date and Last Run date)

    When user picks any date range from Plan year Cycle such as Feb 1- Jan 31 or Apr 1 -March 31 etc. With the help of JavaScript update 'Run Date' field as the current year's starting date from the selected range (01/02/2019 if user select Feb 1 - Jan 31)

    Write a workflow which will run before 90 days. Once required activity is perform, update 'Last Run Date' field same as ' Run Date' in the same workflow or using child workflow

    Now You have 'Last workflow run date', write a business rule to update Run date with 'Last Run date + 365 days' by using formula option. So Run date has the new value and last Run date has the old value. These field will change every time whenever workflow executed.

    Initial : Last Run date - Blank and Run Date- 01/02/2019
    First workflow execution: Last Run date- 01/02/2019 and Run Date - 01/02/2020
    Second time workflow execution: Last Run date-01/02/2020 and Run Date-01/02/2021

    and goes on.....

    Or you can use plugin.

  • USA80 Profile Picture
    26 on at

    So I am using the below script to update a field called Plan year Notification Date.  So when a user picks (for example), 'Jan 1 - Dec 31' from the Plan Year Cycle field, the Plan Year Notification Date gets automatically populated with a date.  Now I need a workflow that will kick off when the Plan Year Notification Date is the same as the current date and then after it runs to up the year by one in the Plan Year Notification date field. Any help is appreciated.

    function UpdatePlanYearNotificationDate()
    {
     var PlanYearCycle = Xrm.Page.getAttribute("nhs_planyearcycle").getSelectedOption();
     if (PlanYearCycle == null || PlanYearCycle =='undefined' || PlanYearCycle =='')
      {
       Xrm.Page.getAttribute("nhs_planyearnotificationdate").setValue();
      }

     else if (PlanYearCycle != null || PlanYearCycle !='undefined' || PlanYearCycle !='')
      {
       var PlanYearCycleText = Xrm.Page.getAttribute("nhs_planyearcycle").getSelectedOption().text; 
       if ((PlanYearCycleText == 'Jan 1 - Dec 31') || (PlanYearCycleText == 'Dec 1 – Nov 30'))
        {
         //var d = new Date(new Date().getFullYear(), 0, 1);
         
         var d = new Date();
         var year = d.getFullYear();
         var month = d.getMonth();
         var day = d.getDate();
         var c = new Date(year, 8, 1) //month from 0-11, January is 0

         Xrm.Page.getAttribute("nhs_planyearnotificationdate").setValue(c);
        }
       else if (PlanYearCycleText == 'Feb 1 - Jan 31')
        {
         //var d = new Date(new Date().getFullYear(), 0, 1);
         
         var d = new Date();
         var year = d.getFullYear();
         var month = d.getMonth();
         var day = d.getDate();
         var c = new Date(year, 10, 1) //month from 0-11, January is 0

         Xrm.Page.getAttribute("nhs_planyearnotificationdate").setValue(c);
        }
       else if (PlanYearCycleText == 'Mar 1 – Feb 28 (29)')
        {
         //var d = new Date(new Date().getFullYear(), 0, 1);
         
         var d = new Date();
         var year = d.getFullYear();
         var month = d.getMonth();
         var day = d.getDate();
         var c = new Date(year, 11, 1) //month from 0-11, January is 0

         Xrm.Page.getAttribute("nhs_planyearnotificationdate").setValue(c);
        }
       else if (PlanYearCycleText == 'Apr 1 – Mar 31')
        {
         //var d = new Date(new Date().getFullYear(), 0, 1);
         
         var d = new Date();
         var year = d.getFullYear();
         var month = d.getMonth();
         var day = d.getDate();
         var c = new Date(year, 0, 1) //month from 0-11, January is 0

         Xrm.Page.getAttribute("nhs_planyearnotificationdate").setValue(c);
        }
       else if (PlanYearCycleText == 'May 1 – Apr 30')
        {
         //var d = new Date(new Date().getFullYear(), 0, 1);
         
         var d = new Date();
         var year = d.getFullYear();
         var month = d.getMonth();
         var day = d.getDate();
         var c = new Date(year, 1, 1) //month from 0-11, January is 0

         Xrm.Page.getAttribute("nhs_planyearnotificationdate").setValue(c);
        } 
       else if (PlanYearCycleText == 'Jun 1 – May 31')
        {
         //var d = new Date(new Date().getFullYear(), 0, 1);
         
         var d = new Date();
         var year = d.getFullYear();
         var month = d.getMonth();
         var day = d.getDate();
         var c = new Date(year, 2, 1) //month from 0-11, January is 0

         Xrm.Page.getAttribute("nhs_planyearnotificationdate").setValue(c);
        } 
       else if (PlanYearCycleText == 'Jul 1 – Jun 30')
        {
         //var d = new Date(new Date().getFullYear(), 0, 1);
         
         var d = new Date();
         var year = d.getFullYear();
         var month = d.getMonth();
         var day = d.getDate();
         var c = new Date(year, 3, 1) //month from 0-11, January is 0

         Xrm.Page.getAttribute("nhs_planyearnotificationdate").setValue(c);
        }  
       else if (PlanYearCycleText == 'Aug 1 – Jul 31')
        {
         //var d = new Date(new Date().getFullYear(), 0, 1);
         
         var d = new Date();
         var year = d.getFullYear();
         var month = d.getMonth();
         var day = d.getDate();
         var c = new Date(year, 4, 1) //month from 0-11, January is 0

         Xrm.Page.getAttribute("nhs_planyearnotificationdate").setValue(c);
        } 
       else if (PlanYearCycleText == 'Sept 1 – Aug 31')
        {
         //var d = new Date(new Date().getFullYear(), 0, 1);
         
         var d = new Date();
         var year = d.getFullYear();
         var month = d.getMonth();
         var day = d.getDate();
         var c = new Date(year, 5, 1) //month from 0-11, January is 0

         Xrm.Page.getAttribute("nhs_planyearnotificationdate").setValue(c);
        }  
       else if (PlanYearCycleText == 'Oct 1 – Sept 30')
        {
         //var d = new Date(new Date().getFullYear(), 0, 1);
         
         var d = new Date();
         var year = d.getFullYear();
         var month = d.getMonth();
         var day = d.getDate();
         var c = new Date(year, 6, 1) //month from 0-11, January is 0

         Xrm.Page.getAttribute("nhs_planyearnotificationdate").setValue(c);
        } 
       else if (PlanYearCycleText == 'Nov 1 – Oct 31')
        {
         //var d = new Date(new Date().getFullYear(), 0, 1);
         
         var d = new Date();
         var year = d.getFullYear();
         var month = d.getMonth();
         var day = d.getDate();
         var c = new Date(year, 7, 1) //month from 0-11, January is 0

         Xrm.Page.getAttribute("nhs_planyearnotificationdate").setValue(c);
        } 
      }
    }

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans