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)

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

I have the same question (0)
  • Suggested answer
    Preeti Sharma Profile Picture
    2,678 on at

    Hi,

    Please try to use common methods available with JavaScript for getting date from month.

    I hope following links will be helpful to you:

    [View:http://www.encodedna.com/javascript/first-and-last-day-of-a-given-month-in-javascript.htm]

    [View:http://www.tutorials2learn.com/tutorials/scripts/javascript/get-last-date-of-the-month-javascript.html]

    Just pass parameters selected from optionsets.

    Thanks.

  • Suggested answer
    Arpit Shrivastava Profile Picture
    7,518 User Group Leader on at

    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

     

  • Nagaraj M Profile Picture
    161 on at

    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

  • Karsten Wirl Profile Picture
    4,477 on at

    Can you post a screenshot of the error message?

  • Nagaraj M Profile Picture
    161 on at

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

    option-set-error.PNG

  • Suggested answer
    Arpit Shrivastava Profile Picture
    7,518 User Group Leader on at

    Hi Nagaraj,

    Here is the anwser of your query:

    community.dynamics.com/.../127876

    Cheers

  • Nagaraj M Profile Picture
    161 on at

    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
    Karsten Wirl Profile Picture
    4,477 on at

    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

    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.

  • Karsten Wirl Profile Picture
    4,477 on at

    community_5F00_range.png

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

    You are online, I use on-premise.

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 March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
AS-17030037-0 Profile Picture

AS-17030037-0 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans