Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Option set with start date and end date field

(0) ShareShare
ReportReport
Posted on by 195

Hi this is Bharath, I have 1 option set with q1,q2,q3,q4 options.i have start date and end date fields.i have to populate start date and end date fields based on q1,q2,q3,q4  using javascript.

example q1 starts at 01-06-2018 and ends at 31-08-2018.like this i want to populate date fields.

Thanks,

Bharath.

*This post is locked for comments

  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,188 Moderator on at
    RE: Option set with start date and end date field

    There are many different ways to do this, but the following logic works pretty well. Of course you can make it better for your needs:

    If you set the values of your option set to 1,2,3,4 corresponding to Q1, Q2, Q3, Q4, you can use the following:

    var selectedQuarter = Xrm.Page.getAttribute("new_quartercode").getValue();

    var startMonth = selectedQuarter * 3 - 2;

    var endMonth = selectedQuarter * 3;

    var lastDayOfMonth = 30;

    if (selectedQuarter == 1 || selectedQuarter == 4)

      lastDayOfMonth = 31;

    var startDate = new Date(yearValue, startMonth -1, 1);

    var endDate = new Date(yearValue, endMonth -1, lastDayOfMonth);

    Xrm.Page.getAttribute("new_startdate").setValue(startDate);

    Xrm.Page.getAttribute("new_enddate").setValue(endDate);

    Hope this helps.

  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at
    RE: Option set with start date and end date field

    In addition to that you can set date file using following syntax

    Xrm.Page.getAttribute(‘fieldname’).setValue(new Date());

  • Verified answer
    Justinjose Profile Picture
    2,707 on at
    RE: Option set with start date and end date field

    Hi bharath,

    You can try something like below code and call function on change of optionset.

    function getOptions() {
        var optionset = Xrm.Page.getAttribute("provide fieldSchemaName here");
        if (optionset != null) {
            //Get OptionSet Text
            alert("OptionSet Text :" + optionset.getText());
            //Get OptionSet Value
            alert("OptionSet Value : " + optionset.getValue());
    
            // Option 1 Switch using optionset value
            switch(optionset.getValue()) {
                case 10000:
                    setDate("pass startDate","pass EndDate");
                    break;
                case 10001:
                    setDate("pass startDate", "pass EndDate");
                    break;
                case 10002:
                    setDate("pass startDate", "pass EndDate");
                    break;
                case 10003:
                    setDate("pass startDate", "pass EndDate");
                    break;
                default:
                    break;
    
                    //Option 2 Switch using optionset text
                    switch(optionset.getText()) {
                        case Q1:
                            setDate("pass startDate","pass EndDate");
                            break;
                        case Q2:
                            setDate("pass startDate", "pass EndDate");
                            break;
                        case Q3:
                            setDate("pass startDate", "pass EndDate");
                            break;
                        case Q4:
                            setDate("pass startDate", "pass EndDate");
                            break;
                        default:
                            break;               
            }
        }
    }
    
    function setDate(startDate, EndDate){
        Xrm.Page.getAttribute("provide fieldSchemaName here").setValue(startDate);
        Xrm.Page.getAttribute("provide fieldSchemaName here").setValue(EndDate);
    }


    Thanks

    Justin Jose

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
dkrishna Profile Picture

dkrishna 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans