web
You’re offline. This is a read only version of the page.
close
Skip to main content
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

I have the same question (0)
  • Suggested answer
    Aric Levin - MVP Profile Picture
    30,190 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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#3
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans