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 :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

How can I automatically add 5 years to a date field?

(0) ShareShare
ReportReport
Posted on by

Hi all, 

Hope everyone is safe and sound. I am new to dynamics and wondered what would be the correct solution to make the system automatically fill in the date field (step 4 in the scenario below)

User scenario:

  1. There are 3 fields for the user to fill in:
    1. Field A - dropdown list
    2. Field B - start date of item's validity
    3. Field C - end date of item's validity

  2. User selects "Yes" from a dropdown list in the field A
  3. User is prompted to enter the start date for the items validity in the field B. For example 2021-07-02
  4. After the user enters the start date in the field B, the system automatically fills in the end date in the field C by adding 5 years to the date entered in field B. For example - 2026-07-02

Could someone please advice if we can write business rules or add a JavaScript to fulfil step 4? Perhaps someone has solved similar challenges?

I have the same question (0)
  • Suggested answer
    Naveen Ganeshe Profile Picture
    3,397 User Group Leader on at

    Hello,

    There are some solutions for your scenario:

    1. Write a Javascript

    2. Write a system workflow

    3. you can make field B a calculated field and add 5 years to it. Please see the below screenshot:

    0285.pastedimage1625182674346v1.png

  • Suggested answer
    Daniel Schneider Profile Picture
    172 on at

    Hi,

    here the code:

    var test = test || {};

    test.Customizing = {

       Load: function () {

           Xrm.Page.getAttribute("your-field-with-value").addOnChange(this.AddYear);

       },

       AddYear: function () {

           var fieldBValue = Xrm.Page.getAttribute("your-field-with-value").getValue();

           var fieldCValue = new Date(fieldBValue.getFullYear() + 5, fieldBValue.getMonth(), fieldBValue.getDate());

           Xrm.Page.getAttribute("your-field-to-update").setValue(fieldCValue);

       }

    };

    add it to js file. Register it on Form to OnLoad Event.

    Greetz

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi, 

    You can create a Calculated field first:

    6786.pastedimage1625469368507v1.png

    4061.pastedimage1625469456444v2.png

    For more details on creating Calculated field, you can refer to this official documentation:

    https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/customize/define-calculated-fields?view=op-9-1

    And then you can create a Business rule to judge whether the Field A is Yes:

    5314.pastedimage1625469543646v3.png

    2043.pastedimage1625469572473v4.png

    For more details on creating business rules, please refer to this official documentation:

    https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/customize/create-business-rules-recommendations-apply-logic-form?view=op-9-1

    This is my result:

    8562.pastedimage1625470103027v5.png

    If this helped you, I'd appreciate it if you'd mark this as a Verified Answer, which may in turn help others as well.

    Best Regards,

    Frank Gong

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 > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Martin Dráb Profile Picture

Martin Dráb 41 Most Valuable Professional

#2
iampranjal Profile Picture

iampranjal 39

#3
Satyam Prakash Profile Picture

Satyam Prakash 35

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans