Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

need to populate the date field based upon year and month as global option set values using javascript

(0) ShareShare
ReportReport
Posted on by 161

Hi team,

I am having two global option sets one is for year and one is for month.

based upon the selection i need to populate one date field with the last date of that particular selected month.

i.e if I select 2018 as year and march as month. 

then my date field should be set as 31/3/2018 ( last date of that month).

kindly provide some links as i am new to use Date time fields in javascript

*This post is locked for comments

  • Suggested answer
    Arpit Shrivastava Profile Picture
    7,518 User Group Leader on at
    RE: need to populate the date field based upon year and month as global option set values using javascript

    Hi Nagaraj,

    Please have a look below article, it may help:

    community.dynamics.com/.../109627

    Cheers

  • Karsten Wirl Profile Picture
    4,477 on at
    RE: need to populate the date field based upon year and month as global option set values using javascript

    community_5F00_range.png

    Okay, but there is an important difference between your situation and mine.

    You are online, I use on-premise.

  • Nagaraj M Profile Picture
    161 on at
    RE: need to populate the date field based upon year and month as global option set values using javascript

    No Karsten,

    It's not advice when i am getting that alert it's clearing my entered data , and saying you must enter in this particular range.

    if possible try once and let me share the screen shot whether you are able to enter your own value.

  • Suggested answer
    Karsten Wirl Profile Picture
    4,477 on at
    RE: need to populate the date field based upon year and month as global option set values using javascript

    Hi.

    Press on "OK" and enter your value... the message shown above is only an advise for you.

  • Nagaraj M Profile Picture
    161 on at
    RE: need to populate the date field based upon year and month as global option set values using javascript

    Hi Arpit,

    Thanks for reply i have seen that post,

    but i want to start my Option set values from 1 , i need this because i want to create Month option set field with values from 1, 2, 3 which will be easy for me to calculate the date value.

    any suggestions please

  • Suggested answer
    Arpit Shrivastava Profile Picture
    7,518 User Group Leader on at
    RE: need to populate the date field based upon year and month as global option set values using javascript

    Hi Nagaraj,

    Here is the anwser of your query:

    community.dynamics.com/.../127876

    Cheers

  • Nagaraj M Profile Picture
    161 on at
    RE: need to populate the date field based upon year and month as global option set values using javascript

    I don't think it's an error it's an alert i am getting from CRM side.

    option-set-error.PNG

  • Karsten Wirl Profile Picture
    4,477 on at
    RE: need to populate the date field based upon year and month as global option set values using javascript

    Can you post a screenshot of the error message?

  • Nagaraj M Profile Picture
    161 on at
    RE: need to populate the date field based upon year and month as global option set values using javascript

    Thanks Arpit

    I want to create an option set with values from 1 to 10 but it's saying me enter between 100,000,000 and 100,009,999 i have tried to change the same in publisher setting for option prefix but it's also not allowing so how we could achieve this .

    please suggest some thing

  • Suggested answer
    Arpit Shrivastava Profile Picture
    7,518 User Group Leader on at
    RE: need to populate the date field based upon year and month as global option set values using javascript

    Hello Nagaraj,

    Please try below code. Apologies in advance for having any syntax issue. 

    // Get Month and Year from Global Option Set Field
    var getYear = Xrm.Page.getAttribute("<Year Option Set Field Schema Name>").getText();

    var getMonth = Xrm.Page.getAttribute("<Month Option Set Field Schema Name>").getText();

    // Get Last date of Month
    var date = new Date();

    var lastDay = new Date(getYear, getMonth + 1, 0);

    var lastDayWithSlashes = (lastDay.getDate()) + '/' + (lastDay.getMonth() + 1) + '/' + lastDay.getFullYear();

    alert(lastDayWithSlashes);

    // Set Last date

    var currentDateTime = new Date();

    Xrm.Page.getAttribute("<date field schema name>").setValue(lastDay);

    If found useful, please mark the answer as verified.


    Cheers
    Arpit
    https://arpitmscrmhunt.blogspot.com

     

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 231,723 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans