locked
Script Help - clearAddress RRS feed

  • Question

  • We have an onChange event script running on our order form. When a user selects the clear check box it clears the address fields. Currently, the user checks the box, it clears the address, they type a new address, uncheck the box and save the record. Can I add a loop to the script so that the checkbox clears itself?

    function clearAddress()
    {
    var clear = Xrm.Page.getAttribute("orbus_clear").getValue();
    if (clear == 1)
    {
    var blank = "";
    Xrm.Page.getAttribute("shipto_name").setValue(blank);
    Xrm.Page.getAttribute("shipto_line1").setValue(blank);
    Xrm.Page.getAttribute("shipto_line2").setValue(blank);
    Xrm.Page.getAttribute("shipto_line3").setValue(blank);
    Xrm.Page.getAttribute("shipto_city").setValue(blank);
    Xrm.Page.getAttribute("shipto_contactname").setValue(blank);
    Xrm.Page.getAttribute("shipto_stateorprovince").setValue(blank);
    Xrm.Page.getAttribute("shipto_postalcode").setValue(blank);
    Xrm.Page.getAttribute("shipto_telephone").setValue(blank);
    Xrm.Page.getAttribute("shipto_fax").setValue(blank);
    Xrm.Page.getAttribute("shipto_country").setValue(blank);
    }
    }

    Thursday, October 16, 2014 1:01 PM

All replies

  • Hi,

    It is possible to set the value for the checkbox even from the event field which fired the function. You could use the setValue for it as you used for other fields. But I think using a button on the ribbon, or using a custom button on the form (unsupported) could help in better user experience.


    Persian Dynamics CRM Community | انجمن متخصصان فارسی زبان

    Thursday, October 16, 2014 1:14 PM
    Moderator
  • Hi,

    It is possible to set the value for the checkbox even from the event field which fired the function. You could use the setValue for it as you used for other fields. But I think using a button on the ribbon, or using a custom button on the form (unsupported) could help in better user experience.


    Persian Dynamics CRM Community | انجمن متخصصان فارسی زبان


    Using a ribbon button is a good approach.  If continue to use the existing Javascript - you could clear the checkbox value at the end of your javascript and maybe even add a setTimeout function of 0.5 second prior clearing it.

    Follow me on Twitter

    Good CRM Links
    My CRM Blog: http://mscrmonline.wordpress.com

    Thursday, October 16, 2014 2:19 PM
    Moderator
  • after Xrm.Page.getAttribute("shipto_country").setValue(blank);, you can set

    orbus_clear to false.- inside the loop.

    I was always setting the value to null. Never knew blank was an option.

    cheers

    Jithesh


    Thursday, October 16, 2014 10:44 PM