Mutually exclusive checkbox fields in ms crm 4.0

Voorgesteld antwoord Mutually exclusive checkbox fields in ms crm 4.0

  • Thursday, May 17, 2012 8:57 AM
     
     

    Hi,

    I have the below requirement

    There are two checkbox fields that are mutually exclusive and the user must select exactly one choice. In other words, clicking a non-selected checkbox field will deselect whatever other check box field was previously selected.

    Any help greatly appriciated!

    Thanks,

    Srikanth Reddy



All Replies

  • Thursday, May 17, 2012 9:03 AM
     
      Has Code

    hi you need to write js,add a function on both the fileds.

    register this one on field1 event and vice versa on field2

    Xrm.Page.getAttribuet("filed2").setValue(false)
    
    Xrm.Page.getAttribuet("filed1").setValue(true);


    By Sanz. -- If you find this post helpful then please "Vote as Helpful" and "Mark As Answer".

  • Thursday, May 17, 2012 9:23 AM
     
     

    Thanks for your quick response! I need to implement this functionality in MS CRM 4.0.

    I don't think it will work OnChange event handler of the fields, how can i do ?

  • Thursday, May 17, 2012 9:48 AM
    Moderator
     
     Proposed Answer

    Hello Srikanth,

    To implement it you can use OnChange event handler with following syntax:

    For first field:

    crmForm.all.<Second field here>.DataValue = !crmForm.all.<First field here>.DataValue;

    For second field:

    crmForm.all.<First field here>.DataValue = !crmForm.all.<Second field here>.DataValue;

    the this is that this script would be triggered only when checkbox will loose focus.


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter


  • Thursday, May 17, 2012 1:51 PM
     
     

    Thanks for your response! I have tried in other way by attaching OnClick event to the checkbox field in OnLoad event of the form. It is working fine for me.

        crmForm.all.us_firstfield.onclick = function()

        {

            if (crmForm.all.us_secondfeld.DataValue==true)

            {

                crmForm.all.us_secondfeld.DataValue=false;

            }

        }

       

       

  • Thursday, May 17, 2012 2:00 PM
    Moderator
     
     Proposed Answer Has Code

    Thanks for your response! I have tried in other way by attaching OnClick event to the checkbox field in OnLoad event of the form. It is working fine for me.

        crmForm.all.us_firstfield.onclick = function()

        {

            if (crmForm.all.us_secondfeld.DataValue==true)

            {

                crmForm.all.us_secondfeld.DataValue=false;

            }

        }

       

       

    Unfortunately your code is not full. Following code will work without issues:

    crmForm.all.us_firstfield.onclick = function()
    {
    	crmForm.all.us_secondfeld.DataValue = !crmForm.all.us_firstfield.DataValue;
    }


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter