locked
Disabling All fields on a Tab RRS feed

  • Question

  • I was wondering if anyone knew the script for disabling all the fields on a particular tab.

    Ideally we want to have a tab on our opportunity form that only certain people in the company can update and save regardless of who the owner is. To accomplish this I've given them a specific role with permission to write on all Opportunities at the orginizational level. So i'm looking to disable the fields on the opportunity form that they shouldn't be able to edit but instead of doing it by single field i was looking to disable whole tabs instead.

    any help is appreciated. CRM 4.0.
    Monday, August 31, 2009 6:59 PM

Answers

  • Hi,

    So, you can disable the lookups separately (if this is acceptable), if you decide to use this code.
    However, you may also use the code proposed in one of the other posts to disable all the fields in the particular tab:

    var el=document.getElementById('Tab2');
    
    function toggleDisabled(el) {
      try {
        el.disabled = el.disabled ? false : true;
      }
      catch(E){}
                    
      if (el.childNodes && el.childNodes.length > 0)  
      {
        for (var x = 0; x < el.childNodes.length; x++) 
        {
          toggleDisabled(el.childNodes[x]);
        }
      }
    }
    
    toggleDisabled(el);
    


    I hope that will help now :)

    Best regards,
    Kuba
    -- Kuba Skałbania, Netwise
    Monday, August 31, 2009 9:16 PM

All replies

  • Hi,

    The following code will let you disable all the fields on a form (not on one tab). However, you may try playing with it to disable only fields from one tab:

    for (var index in crmForm.all) 
    {
      var control = crmForm.all[index];
      if (control.Disabled != null) 
      {
        control.Disabled = true;
      }
    }
    

    I hope that helps,
    Kuba
    -- Kuba Skałbania, Netwise
    Monday, August 31, 2009 7:08 PM

  • Hi Check this url
    http://www.dotnetspider.com/resources/20363-Disable-CRM-TABS-Completely.aspx

    It is for CRM 3.0 but i think it will work for CRM 4.0 as well.

    If you want to show/hide tab at runtime then check this.
    http://blogs.msdn.com/midatlanticcrm/archive/2006/01/02/Dynamically-Showing-or-Hiding-Tabs-in-Microsoft-CRM-3.aspx
    Monday, August 31, 2009 7:14 PM
  • That's the code i had before and it disabled all the fields but the lookup fields from different relationships to other forms. For example all of my lookup fields to the User table where still writeable.
    Monday, August 31, 2009 7:21 PM
  • Hi,

    So, you can disable the lookups separately (if this is acceptable), if you decide to use this code.
    However, you may also use the code proposed in one of the other posts to disable all the fields in the particular tab:

    var el=document.getElementById('Tab2');
    
    function toggleDisabled(el) {
      try {
        el.disabled = el.disabled ? false : true;
      }
      catch(E){}
                    
      if (el.childNodes && el.childNodes.length > 0)  
      {
        for (var x = 0; x < el.childNodes.length; x++) 
        {
          toggleDisabled(el.childNodes[x]);
        }
      }
    }
    
    toggleDisabled(el);
    


    I hope that will help now :)

    Best regards,
    Kuba
    -- Kuba Skałbania, Netwise
    Monday, August 31, 2009 9:16 PM
  • You might want to consider creating a custom entity for those specific fields, then give access as necessary via security role. This provides more robust data security model.  For convenient data viewing, an iFrame can be used and placed in a tab for displaying those field values in read-only mode.
    Henri
    Tuesday, September 1, 2009 5:13 AM
  • Thanks for the marvelous script Kuba...it worked like a charm.
    Thursday, September 3, 2009 3:02 PM
  • You might want to consider creating a custom entity for those specific fields, then give access as necessary via security role. This provides more robust data security model.  For convenient data viewing, an iFrame can be used and placed in a tab for displaying those field values in read-only mode.
    Henri

    The CRM data model is not too strong on 1-to-1 relationships.

    Why not hide the whole tab in the OnLoad event?

    function hideTab(tabText) {
    /********************************************************************************
    * Hide the specified Tab
    *
    * Arguments: the name of the Tab
    * Dependent Functions: None
    * returns: HTMLelement representing the Tab
    *
    */
        var tabBar = document.getElementById("crmTabBar");
        if (tabBar) {
            var tabs = tabBar.childNodes;		
    		
            for (var i = 0, len = tabs.length; i < len; i++) {
                var currentTab = tabs[i];
                if (currentTab.innerText == tabText) {
                    currentTab.style.display = 'none';
                    return currentTab;
                }
            }
        }
    }
    // End Of Function
    
    Thursday, September 3, 2009 3:29 PM
  • You're welcome! I'm glad I could help.

    Kuba
    -- Kuba Skałbania, Netwise
    Thursday, September 3, 2009 6:41 PM