Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

Adding a year field drop down list - year only field

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi,

i have to add a company established date field in CRM form with the following requirement. 

Year will be a 4 digit number drop-down list.
Any number is acceptable up to the current year.
How i can add a field to display upto the current year?
thank you, Siva
  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Adding a year field drop down list - year only field

    Hi Siva,

    You can use regex validation for year to address here are some of the links which may be helpful to you.

    1. https://www.regextester.com/93651

    2. https://www.py4u.net/discuss/340793

    3. https://stackoverflow.com/questions/17547710/javascript-regex-validate-years-in-range

    If you can get exact regex using above link then you can just check with Regex.Match to address your requirement.

    If not then you can perform below operation-

    1. Check Regex.Match with 4 digit number ^[12][0-9]{3}$ ( Validate from 1000 - 2999)

    2. After above regex check you can validate it with current year using -> new Date().getFullYear()

    3. Code will be some how as below,

    function Year_Validation(input)
    {
      var Year = /^[12][0-9]{3}$/;
      if((input.value.match(year))
            {
    currentYear =
    new Date().getFullYear();

    if(currentYear <= input){
            // Perform Operation
    }
    } else { alert("This is not a valid year"); } }

    Hope this help you, If it is helpful pls mark as Verified Answer, which will help others as well. Thanks!

  • Suggested answer
    RE: Adding a year field drop down list - year only field

    Hi Siva,

    You can find a a step-by-step guide to add events listeners and validation here: www.languagetechfunda.com/.../validate-end-date-greater-start-date-dynamics-crm

    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. 

    Thank you. 

  • SivaR Profile Picture
    SivaR 34 on at
    RE: Adding a year field drop down list - year only field

    Yes, i have to include the year field in the Entity's main form and save the value.

    Thank you,

    Siva

  • Nya Profile Picture
    Nya 29,058 on at
    RE: Adding a year field drop down list - year only field

    Hi Siva,

    Would you please indicate whether you need to insert the Year field into an entity's Main form or a Marketing Form?

     

    Best Regards,

    Nya

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,160 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans