locked
Javascript after Upgrading to CRM 4.0 RRS feed

  • Question

  • Hi,

     

    Just wondering if anybody knows why when I run an upgrade from CRM 3.0 to CRM 4.0 javascripts I have written to hide fields based on user selection through out an record doesn't work.  Currently all the fields are visable and enabled.

     

    They work fine in CRM 3.0 but not when I upgrade.

     

    Thanks,

    Matthew.

    Friday, February 8, 2008 6:04 AM

Answers

  • Hi.

     

    You can use these utility functions to Show/Hide or Disable/Enable Controls.

     

    Code Snippet

     

    function OnCrmPageLoad()

    {

                //Show / Hide

                //DisplayControl( "new_carootid" , DisplayType.None );

                //DisplayControl( "new_customertype" , DisplayType.None );

               

                // Disable / Enable

                //DisableControl( "new_lastname" , true );

                //DisableControl( "new_customertype" , true );

                //DisableControl( "new_carootid" , true );

    }

     

    var DisplayType = { None : "None" , Inline : "Inline" }

     

    function DisplayControl( controlId , displayType )

    {

                var getElement = document.getElementById;

               

                //Control Container (TD)

                var control_d = getElement( controlId + "_d" );

                if( control_d )

                   control_d.style.display = displayType;

               

                //Control Label

                var control_c = getElement( controlId + "_c" );

                if( control_c )

                   control_c.style.display = displayType;

                           

                var control   = getElement( control );

                if( control )

                    control.style.display = displayType;

    }

     

    function DisableControl( controlId , disabled )

    {

                var control = document.getElementById( controlId );

                if( control )

                   control.Disabled = disabled;    

    }

     

    OnCrmPageLoad();

     

     

     

    This should work in both CRM 3.0 and 4.0.

    Cheers,

     

    Adi

     

    Monday, February 11, 2008 4:32 PM

All replies

  • Dear Mattew,

     

    see my post on http://microsoftcrm3.blogspot.com

     

    Thursday, January 31, 2008

    Hide Tab , Button base on Security Role in Javascript in CRM 4.0

     

    You have to update your web services in javascript after upgrade.

     

    Best Regards,

    Imran

     

    http://microsoftcrm3.blogspot.com

     

    Friday, February 8, 2008 7:27 AM
    Moderator
  • Can you post the code; it depends how you were hiding the fields.

     

    Be aware that there was no supported way to hide fields in CRM 3.0, so there was no guarantee the cod ewould still work

    Friday, February 8, 2008 7:42 AM
    Moderator
  • David,

     

    This is a sample from the code that I have which shows some fields being hidden and displayed.

     

    Code Snippet

    //hiding Relocation Section

    crmForm.all.edv_existingaddress.parentElement.parentElement.parentElement.style.display = 'none';

    //hiding Business Broadband and Bigpond Options

    crmForm.all.edv_bbtidworkrequired.parentElement.parentElement.parentElement.style.display = 'none';

    crmForm.all.edv_bbtidstarterallowance.parentElement.parentElement.parentElement.style.display = 'none';

    crmForm.all.edv_bbtidadvantagespeed.parentElement.parentElement.parentElement.style.display = 'none';

    crmForm.all.edv_bbtidbigacctno.parentElement.parentElement.parentElement.style.display = 'none';

    crmForm.all.edv_existingaddress.parentElement.parentElement.parentElement.style.display = 'none';

    //hiding all Winback options

    crmForm.all.edv_winbackqtysvc.parentElement.parentElement.parentElement.style.display = 'none';

    crmForm.all.edv_winbackopt1.parentElement.parentElement.parentElement.style.display = 'none';

    crmForm.edv_winbacksvcno1.parentElement.parentElement.parentElement.style.display = 'none';

    //hiding Single Bill Section

    crmForm.all.edv_pstnservicestomodify.parentElement.parentElement.parentElement.style.display = 'none';

    // End of hiding Service Sections

    /* This section will disable all manditory fields that are based on other selections. This section does not

    disable manditory fields that must be filled in for all orders. */

    //PSTN

    crmForm.all.edv_inplacenumber.Disabled = true

    crmForm.all.edv_pstnworkrequired.Disabled = true

    crmForm.all.edv_pstnserviceqty.Disabled = true

    //ISDN2

    crmForm.all.edv_isdn2serviceqty.Disabled = true

    crmForm.all.edv_isdn2workrequired.Disabled = true

    crmForm.all.edv_isdn2product.Disabled = true

    crmForm.all.edv_isdn2indialpreference.Disabled = true

    crmForm.all.edv_isdn2numberrange.Disabled = true

    //ISDN30

    crmForm.all.edv_isdn30workrequired.Disabled = true

    crmForm.all.edv_isdn30serviceqty.Disabled = true

    crmForm.all.edv_isdn30channels.Disabled = true

    crmForm.all.edv_isdn30indialpreference.Disabled = true

    crmForm.all.edv_isdn30norangepref.Disabled = true

    //Relocation Requirements

    crmForm.all.edv_existingaddress.Disabled = true

    //Business Broadband

    crmForm.all.edv_bbtidadvantagedownload.Disabled = true

    crmForm.all.edv_bbtidadvantagespeed.Disabled = true

    crmForm.all.edv_bbtidbdslallow.Disabled = true

    crmForm.all.edv_bbtidbigacctno.Disabled = true

    crmForm.all.edv_bbtidbigpondadslfnn.Disabled = true

    crmForm.all.edv_bbtidbigpondusername.Disabled = true

    crmForm.all.edv_bbtidcontractterm.Disabled = true

    crmForm.all.edv_bbtidexistacctno.Disabled = true

    crmForm.all.edv_bbtidexistingfnn.Disabled = true

    crmForm.all.edv_bbtidinstallationtype.Disabled = true

    crmForm.all.edv_bbtidplantype.Disabled = true

    crmForm.all.edv_bbtidsiteaddress.Disabled = true

    crmForm.all.edv_bbtidstarterallowance.Disabled = true

    crmForm.all.edv_bbtidstarterspeed.Disabled = true

    crmForm.all.edv_bbtidworkrequired.Disabled = true

    //Winback

    crmForm.all.edv_winbackqtysvc.Disabled = true

    crmForm.all.edv_winbackcallingplan.Disabled = true

    crmForm.all.edv_winbackexistsupp.Disabled = true

    crmForm.all.edv_winbackcurrentacct.Disabled = true

    crmForm.all.edv_winbackexistacct.Disabled = true

    crmForm.all.edv_winbacktlscharge.Disabled = true

    crmForm.all.edv_winbackopt1.Disabled = true

    crmForm.all.edv_winbackopt2.Disabled = true

    crmForm.all.edv_winbackopt3.Disabled = true

    //Winback Service Numbers

    crmForm.all.edv_winbacksvcno1.Disabled = true

    crmForm.all.edv_winbacksvcno2.Disabled = true

    crmForm.all.edv_winbacksvcno3.Disabled = true

    crmForm.all.edv_winbacksvcno4.Disabled = true

    crmForm.all.edv_winbacksvcno5.Disabled = true

    crmForm.all.edv_winbacksvcno6.Disabled = true

    crmForm.all.edv_winbacksvcno7.Disabled = true

    crmForm.all.edv_winbacksvcno8.Disabled = true

    // End Manitory Fields

    // This will allow user to select related project if the related entity box is ticked.

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

    {

    crmForm.all.edv_relatedprojectid.Disabled = false;

    crmForm.all.edv_relatedprojectid.src = '/_imgs/btn_on_lookup.gif';

    }

    else

    {

    crmForm.all.edv_relatedprojectid.disable = true;

    crmForm.all.edv_relatedprojectid.src = '/_imgs/btn_dis_lookup.gif';

    }

    // This will confirm that user wishes to proceed with sending order to MAC

    crmForm.all.edv_submittomac.onclick = function()

    {

    if(crmForm.all.edv_submittomac.checked==true)

    {

    var truthBeTold = confirm("By proceeding this order will be sent to MAC for processing");

    if (truthBeTold)

    {

    crmForm.all.edv_submittomac.DataValue=true;

    }

    else

    {

    crmForm.all.edv_submittomac.DataValue=false;

    }

    }

    else

    {

    }

    }

    // This will allow MAC to view Processing Checklist Tab when order submitted to MAC

    // onSave this will open up the MAC Checklist once user has completed the order and sent to MAC

    if(crmForm.all.edv_submittomac.checked==true)

    {

    crmForm.all.tab1Tab.style.display = "inline";

    }

    else

    {

    crmForm.all.tab1Tab.style.display = "none";

    }

    // This section of script will reopen necessary service sections based on the Service Type selected by the user

    // Display PSTN Options

    if(crmForm.all.edv_servicetyperequired.options[crmForm.all.edv_servicetyperequired.selectedIndex].text =="PSTN")

    {

    crmForm.all.edv_pstnworkrequired.parentElement.parentElement.parentElement.style.display = "inline";

    crmForm.all.edv_inplacenumber.parentElement.parentElement.parentElement.style.display = "inline";

    crmForm.all.edv_inplacenumber.Disabled = false

    crmForm.all.edv_pstnworkrequired.Disabled = false

    crmForm.all.edv_pstnserviceqty.Disabled = false

    }

    else

    {

    crmForm.all.edv_pstnworkrequired.parentElement.parentElement.parentElement.style.display = "none";

    crmForm.all.edv_inplacenumber.parentElement.parentElement.parentElement.style.display = "none";

    crmForm.all.edv_inplacenumber.Disabled = true

    crmForm.all.edv_pstnworkrequired.Disabled = true

    crmForm.all.edv_pstnserviceqty.Disabled = true

    }

     

     

    Matthew.
    Saturday, February 9, 2008 4:47 AM
  • Hi.

     

    The Problem is DOM related. Microsoft changed to structure of the HTML Document Object Model.

    So a statement like:
    crmForm.all.edv_pstnworkrequired.parentElement.parentElement.parentElement.style.display = "none";

    Might not exist, witch means that one of the parentElements is null;

     

    Use the debugger; keyword at the top of the script and see exactly where it falls.

    You will need to uncheck "disable script debugging for internet explorer under tools --> internet option --> advanced tab.

     

    Cheers

    Adi

     

    Sunday, February 10, 2008 1:22 AM
  • Adi,

    This would appear to be the problem.  Just wondering if anybody knows what command you can use in the new version of CRM that will hide and disable fields based on other information selected.

     

    Thanks,

     

    Matthew.

    Monday, February 11, 2008 1:09 AM
  • Hi.

     

    You can use these utility functions to Show/Hide or Disable/Enable Controls.

     

    Code Snippet

     

    function OnCrmPageLoad()

    {

                //Show / Hide

                //DisplayControl( "new_carootid" , DisplayType.None );

                //DisplayControl( "new_customertype" , DisplayType.None );

               

                // Disable / Enable

                //DisableControl( "new_lastname" , true );

                //DisableControl( "new_customertype" , true );

                //DisableControl( "new_carootid" , true );

    }

     

    var DisplayType = { None : "None" , Inline : "Inline" }

     

    function DisplayControl( controlId , displayType )

    {

                var getElement = document.getElementById;

               

                //Control Container (TD)

                var control_d = getElement( controlId + "_d" );

                if( control_d )

                   control_d.style.display = displayType;

               

                //Control Label

                var control_c = getElement( controlId + "_c" );

                if( control_c )

                   control_c.style.display = displayType;

                           

                var control   = getElement( control );

                if( control )

                    control.style.display = displayType;

    }

     

    function DisableControl( controlId , disabled )

    {

                var control = document.getElementById( controlId );

                if( control )

                   control.Disabled = disabled;    

    }

     

    OnCrmPageLoad();

     

     

     

    This should work in both CRM 3.0 and 4.0.

    Cheers,

     

    Adi

     

    Monday, February 11, 2008 4:32 PM
  • Your code does not work....

     

    Error: Object Expected

     

    Wednesday, March 19, 2008 6:20 PM
  • Witch line?  How did you implement it?

     

    Post your onload implementation here and I'll fix it in a sec.

     

    Cheers,

    Adi

     

    Wednesday, March 19, 2008 6:27 PM
  •  Imran - mscrmexpert wrote:

    Dear Mattew,

     

    see my post on http://microsoftcrm3.blogspot.com

     

    Thursday, January 31, 2008

    Hide Tab , Button base on Security Role in Javascript in CRM 4.0

     

    You have to update your web services in javascript after upgrade.

     

    Best Regards,

    Imran

     

    http://microsoftcrm3.blogspot.com

     

    i also want to hide some field ,but it doesn't work.

     

    i used : crmForm.all.new_myaddress.style.display = 'none';

     

    it doesn't work when i use  Adi's code  ,  is it the problem of  "You have to update your web services in javascript after upgrade."

     

    the first time of putting my question in english , wish somebody can understand  Stick out tongue

     

    Thanks,

     

    Sunday, June 8, 2008 9:17 PM