locked
Required fields according to dropdown RRS feed

  • Question

  • Hi,

    I would like to make a number of fields required dependant on a certain value from a dropdownlist.

    Any ideas on how to achieve this in CRM 2011 online?

    Thanks In Advance

    Monday, August 15, 2011 11:40 AM

Answers

  • create a webresource of javascript type.

    create a function in it and add those code lines in it.

    then open the form in design mode (customization mode). add the reference to the webresource and on change event of the picklist call the function.

    I hope this help.


    Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/
    • Proposed as answer by Amreek Singh Tuesday, August 16, 2011 2:00 PM
    • Marked as answer by tango2310 Monday, September 26, 2011 9:32 PM
    Tuesday, August 16, 2011 2:00 PM

All replies

  • if ( Xrm.Page.data.entity.attributes.get(“picklistfield”).getValue()=="value")

    {

    var field = Xrm.Page.data.entity.attributes.get("fieldname");

    field.setRequiredLevel("required");

    }

    I hope this works.

     

     


    Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/

     

    • Proposed as answer by Amreek Singh Monday, August 15, 2011 12:23 PM
    Monday, August 15, 2011 12:23 PM
  • Thanks Amreek,

    Where do I put this?

    On field A that has the drop down or on fields B, C & that are now required if Field A selection is XYZ?

    Thanks in advance

    Monday, August 15, 2011 11:52 PM
  • Hi,

    You need to put the code into the Field A (Drop Down) Onchange Event.

    You should also set field as not required if drop down field value will be changed to another value and can also compare by field text as below:

     

    // Picklist field comparison by Text label or if you want by value then just use getValue() instead of getText()
    if ( Xrm.Page.data.entity.attributes.get(“picklistfield”).getText() == "Value 1")
    {

     var field = Xrm.Page.data.entity.attributes.get("fieldname");

     

     field.setRequiredLevel("required"); 
    

     

    }

    else if ( Xrm.Page.data.entity.attributes.get(“picklistfield”).getText() == "Value 2")

    {

     var field = Xrm.Page.data.entity.attributes.get("fieldname");

     field.setRequiredLevel("none");

    }


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Tuesday, August 16, 2011 12:08 AM
  • Thanks for your reply

    Sorry but Im a little new to this.

    How do you put code in onchange event in crm 2011 online?

    Thanks in advance

    Tuesday, August 16, 2011 12:42 AM
  • Hi,

    You can add the JScript webresource as per mentioned in the following post: http://crmconsultancy.wordpress.com/2010/10/19/form-scripting-in-crm-2011/ , instead of performing step 6  in Form, double click on the field and go to Events Tab and click on add button and type funciton name


    Jehanzeb Javeed

    http://worldofdynamics.blogspot.com
    Linked-In Profile |CodePlex Profile

    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".
    Tuesday, August 16, 2011 6:37 AM
  • Thanks,

    Will review.

    Tuesday, August 16, 2011 10:20 AM
  • create a webresource of javascript type.

    create a function in it and add those code lines in it.

    then open the form in design mode (customization mode). add the reference to the webresource and on change event of the picklist call the function.

    I hope this help.


    Amreek singh Senior CRM Consultant CDC Praxa Sydney,Australia http://mscrmshop.blogspot.com/
    • Proposed as answer by Amreek Singh Tuesday, August 16, 2011 2:00 PM
    • Marked as answer by tango2310 Monday, September 26, 2011 9:32 PM
    Tuesday, August 16, 2011 2:00 PM
  • Thanks Everyone
    Monday, September 26, 2011 9:33 PM