locked
Hide Add Existing Contact button in CRM4 on Account Form RRS feed

  • Question

  • Hello,

    In CRM4, when I go to the account window, I want to hide the "Add Existing Contact" button. I found the below code on the internet and pasted it on the Onload Event of Account form. But the button does not hide. Can anyone please help on this. Thank you. Jack

     

     


    function HideAssociatedViewButtons(loadAreaId, buttonTitles)
      {
        var navElement = document.getElementById('nav_' + loadAreaId);
        if (navElement != null)
        {
          navElement.onclick = function LoadAreaOverride()
          {
            // Call the original CRM method to launch the navigation link and create area iFrame
            loadArea(loadAreaId);
            HideViewButtons(document.getElementById(loadAreaId + 'Frame'), buttonTitles);
          }
        }
      }

    function HideViewButtons(Iframe, buttonTitles)
    {
      if (Iframe != null )
      {
        Iframe.onreadystatechange = function HideTitledButtons()
        {
          if (Iframe.readyState == 'complete')
          {
            var iFrame = frames[window.event.srcElement.id];
            var liElements = iFrame.document.getElementsByTagName('li');

            for (var j = 0; j < buttonTitles.length; j++)
            {
              for (var i = 0; i < liElements.length; i++)
              {
                if (liElements[i].getAttribute('title') == buttonTitles[j])
                {
                  liElements[i].style.display = 'none';
                  break;
                }
              }
            }
          }
        }
      }
    }


    HideAssociatedViewButtons('account_contacts', ['Add existing Contact to this record']); //To hide Existing Button.

    Tuesday, November 15, 2011 2:43 AM

Answers

  • Hello Jack,

    I modified provided code and it worked for me:

    function HideAssociatedViewButtons(loadAreaId, IFrameId, buttonTitles)
      {
        var navElement = document.getElementById(loadAreaId);
        if (navElement != null)
        {
          navElement.onclick = function LoadAreaOverride()
          {
            // Call the original CRM method to launch the navigation link and create area iFrame
            loadArea(IFrameId);
            HideViewButtons(document.getElementById(IFrameId + 'Frame'), buttonTitles);
          }
        }
      }
    
    function HideViewButtons(Iframe, buttonTitles)
    {
      if (Iframe != null )
      {
        Iframe.onreadystatechange = function HideTitledButtons()
        {
          if (Iframe.readyState == 'complete')
          {
            var iFrame = frames[window.event.srcElement.id];
            var liElements = iFrame.document.getElementsByTagName('li');
    
            for (var j = 0; j < buttonTitles.length; j++)
            {
              for (var i = 0; i < liElements.length; i++)
              {
                if (liElements[i].getAttribute('title') == buttonTitles[j])
                {
                  liElements[i].style.display = 'none';
                  break;
                }
              }
            }
          }
        }
      }
    }
    
    
    HideAssociatedViewButtons('navContacts', 'areaContacts', ['Add existing Contact to this record']); //To hide Existing Button.
    



    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter
    Saturday, November 19, 2011 10:40 AM
    Moderator

All replies

  • Loadareaid is wrong

    try this

    HideAssociatedViewButtons('areaContacts', ['Add existing Contact to this record']); //To hide Existing Button.

    I hope this helps.


    If you find this post helpful then please "Vote as Helpful" and "Mark As Answer". Amreek Singh Senior CRM Consultant CDC Praxa Sydney, Australia http://mscrmshop.blogspot.com http://crm2011usersettings.codeplex.com
    • Proposed as answer by Amreek Singh Tuesday, November 15, 2011 3:15 AM
    Tuesday, November 15, 2011 3:15 AM
  • Thanks. I tried but that did not work either.

    Jack

    Tuesday, November 15, 2011 3:55 AM
  • hello,

    Can anyone help me on this? I am not sure why the above code is not working for me.

     

    Jack

    Friday, November 18, 2011 5:15 AM
  • Hello Jack,

    I modified provided code and it worked for me:

    function HideAssociatedViewButtons(loadAreaId, IFrameId, buttonTitles)
      {
        var navElement = document.getElementById(loadAreaId);
        if (navElement != null)
        {
          navElement.onclick = function LoadAreaOverride()
          {
            // Call the original CRM method to launch the navigation link and create area iFrame
            loadArea(IFrameId);
            HideViewButtons(document.getElementById(IFrameId + 'Frame'), buttonTitles);
          }
        }
      }
    
    function HideViewButtons(Iframe, buttonTitles)
    {
      if (Iframe != null )
      {
        Iframe.onreadystatechange = function HideTitledButtons()
        {
          if (Iframe.readyState == 'complete')
          {
            var iFrame = frames[window.event.srcElement.id];
            var liElements = iFrame.document.getElementsByTagName('li');
    
            for (var j = 0; j < buttonTitles.length; j++)
            {
              for (var i = 0; i < liElements.length; i++)
              {
                if (liElements[i].getAttribute('title') == buttonTitles[j])
                {
                  liElements[i].style.display = 'none';
                  break;
                }
              }
            }
          }
        }
      }
    }
    
    
    HideAssociatedViewButtons('navContacts', 'areaContacts', ['Add existing Contact to this record']); //To hide Existing Button.
    



    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Follow Andriy on Twitter
    Saturday, November 19, 2011 10:40 AM
    Moderator
  • Hello Andriy,

    That worked for me. Thank you very much.

    Jack

    Monday, November 21, 2011 4:04 AM