web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Conditional Drop Down Fields

(0) ShareShare
ReportReport
Posted on by

Is there a way I could make a comment box show based on the selection I choose for example I have the following options in my picklist

Apple

Orange

Pear

Banana

Lets say I want the comment box to show when I choose Pear and Banana, upon selection I will need the comment box to appear and be required.

Is this possible?

Thanks, 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Syed Ibrahim Profile Picture
    6,257 on at

    Two appach

    1.Use business rules

    [View:https://www.linkedin.com/pulse/hide-fields-sections-business-rules-microsoft-crm-online-hans-carlson]

    2. Use JS

    [View:https://danielbergsten.wordpress.com/2011/02/15/crm-2011-javascript-for-hiding-a-field-based-on-another-fields-value/]

    To set field as required use below code.

    Xrm.Page.getAttribute("new_fieldname").setRequiredLevel("required");

  • Community Member Profile Picture
    on at

    Thanks, is there a line of code I will have to use for the comment box? I know for the pick list there is a id code in the background. But what about for an actual field?

  • Suggested answer
    Syed Ibrahim Profile Picture
    6,257 on at

    You just replace new_filedname by your field. say new_comment.

    Hope this helps. If suggestion resolved your query Mark it as verified to close the thread

  • Community Member Profile Picture
    on at

    Based off of my example with the fruit:

    Lets say I have a field titled "Fruit" - Where would I insert this column on the JavaScript?

    Here?

    function SetControlInvisible(Fruit, dependantField) {

       //get control for field

       var control = Xrm.Page.ui.controls.get(field);

       if ((control != “undefined”) && (control != null))

       {

    **************************************************************

    function SetControlInvisible(field, dependantField) {

       //get control for field

       var control = Xrm.Page.ui.controls.get(field);

       if ((control != “undefined”) && (control != null))

       {

           //get control for dependant field

           var dependantControl = Xrm.Page.ui.controls.get(dependantField);

           if ((dependantControl != “undefined”) && (dependantControl != null)) {

               var attribute = dependantControl.getAttribute();

               var depandantFieldValue = attribute.getValue();

               //set visible based on depandant fields value

               if (depandantFieldValue == false) {

                   control.setVisible(false);

               }

               else {

                   control.setVisible(true);

               }

           }

           else {

               alert(‘control not found ‘ + dependantField);

           }

       }

       else {

           alert(‘control not found ‘ + field);

       }

    }

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi afedwards ,

    please try the following code:

    function FormOnLoad()
    {
        Xrm.Page.getAttribute('new_myoptionset').addOnChange(MyOptionSetOnChange);
    }
    
    function MyOptionSetOnChange() {
        var new_myoptionset_value = Xrm.Page.getAttribute("new_myoptionset").getValue();
        if (new_myoptionset_value == 1) // banana
        {
            Xrm.Utility.alertDialog("You have selected a Banana", null)
        }
        else if (new_myoptionset_value == 2) // apple
        {
            Xrm.Utility.alertDialog("You have selected an Apple", null)
        }
    }

    Let me know.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Community Member Profile Picture
    on at

    Thanks, that worked, how can I had an additional field for a comment; Lets say that I selected Apple, then wanted the be able to comment on how much I like apples and it was required that I do so. Could I have a field that is conditional depending on what item I choose?

  • Verified answer
    Community Member Profile Picture
    on at

    Hi afedwards,

    please remember to mark answer as Verified.

    You have to add a comment per value and then you should use the following code:

    function FormOnLoad()
    {
        Xrm.Page.ui.controls.get('new_bananacomment').setDisabled(true);
        Xrm.Page.ui.controls.get('new_appleacomment').setDisabled(true);
        Xrm.Page.getAttribute('new_myoptionset').addOnChange(MyOptionSetOnChange);
    }
    
    function MyOptionSetOnChange() {
        var new_myoptionset_value = Xrm.Page.getAttribute("new_myoptionset").getValue();
        if (new_myoptionset_value == 1) // banana
        {
            Xrm.Utility.alertDialog("You have selected a Banana", null);
            Xrm.Page.ui.controls.get('new_bananacomment').setDisabled(false);
            Xrm.Page.getAttribute('new_bananacomment').setRequiredLevel('required');
        }
        else if (new_myoptionset_value == 2) // apple
        {
            Xrm.Utility.alertDialog("You have selected an Apple", null);
            Xrm.Page.ui.controls.get('new_appleacomment').setDisabled(false);
            Xrm.Page.getAttribute('new_applecomment').setRequiredLevel('required');
        }
    }

    Please let me know if you solve.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Community Member Profile Picture
    on at

    So is the name of my field "new_myoptionset"

  • Suggested answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    you can use my dependent optionset solution

    crmoptionsets.azurewebsites.net

  • MDS Profile Picture
    1,788 on at

    I'd definitely recommend Guido's solution, it's fabulous.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans