Skip to main content

Notifications

Announcements

No record found.

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 Profile Picture
    Aric Levin 30,188 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
    Mahendar Pal 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
    Justinjose 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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans