none
Change 'New button'

    Question

  • How do I change the 'New xxx button' to read 'Change xxx button'? Is that possible?

    Thanks


    Apps
    Tuesday, September 07, 2010 2:52 PM

Answers

  • yes, the script that we have provided you is basically to hide, but you can change this script to rename button.

    you have to chage the below lines then I will rename the button

     

     liElements[i].style.display = ‘none’;

    with

    liElements[i].title='Change xxx button';

     


    Mahain : http://mahenderpal.wordpress.com
    • Marked as answer by Jim Glass Jr Monday, November 29, 2010 8:31 PM
    Tuesday, September 07, 2010 4:03 PM
    Moderator
  • Since you've already established the view in an Iframe, your use of "HideAssociatedViewButtons" is incorrect.  Instead, directly call "HideViewButtons", and pass the Iframe element as the first parameter.  Example (and updated version of HideViewButtons that allows for partial button titles):

    function HideViewButtons(Iframe, buttonTitles) {
     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').substr(0, buttonTitles[j].length) == buttonTitles[j]) {
          liElements[i].style.display = 'none';
          break;
         }
        }
       }
      }
     }
     
     Iframe.attachEvent("onreadystatechange", HideTitledButtons);
    }
    
    HideViewButtons(crmForm.all.IFRAME_Something, new Array("Add existing"));
    


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Friday, November 19, 2010 8:52 PM
    Moderator
  • I have posted my current code-set for the functionality to hide buttons , or to rename them , on my blog .  I've modified the code heavily from what I have posted here to make the code a little more modular.
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Monday, November 29, 2010 9:46 PM
    Moderator

All replies

  • you can track down that button using following script...

    http://blog.davehawes.com/post/2008/04/24/MSCRM-4-Remove-Add-Existing-xxxxx-button.aspx

    http://mscrm-chandan.blogspot.com/2009/09/script-for-hide-add-existing-button.html

    and then since above script is to hide button rather then hiding just chnage the title of the button..

    so  just need to replace

    liElements[i].style.display = 'none';

    with

    liElements[i].innerText = 'NewLabel';

    Hope this helps..

     


    MayankP My Blog My twitter
    • Proposed as answer by Mayank Pujara Tuesday, September 07, 2010 5:04 PM
    Tuesday, September 07, 2010 3:00 PM
  • Hey,

    you have to use below script,

    http://mahenderpal.wordpress.com/2009/06/26/hide-add-existing-button/

    But you need to change

     liElements[i].style.display = ‘none’;

    with

    liElements[i].title='Change xxx button';

     


    Mahain : http://mahenderpal.wordpress.com
    Tuesday, September 07, 2010 3:00 PM
    Moderator
  • OK. Because I did not want to hide the New button, I just want to change how it reads.

    Thanks for your quick response


    Apps
    Tuesday, September 07, 2010 3:11 PM
  • Thanks for your quick response


    Apps
    Tuesday, September 07, 2010 3:12 PM
  • yes, the script that we have provided you is basically to hide, but you can change this script to rename button.

    you have to chage the below lines then I will rename the button

     

     liElements[i].style.display = ‘none’;

    with

    liElements[i].title='Change xxx button';

     


    Mahain : http://mahenderpal.wordpress.com
    • Marked as answer by Jim Glass Jr Monday, November 29, 2010 8:31 PM
    Tuesday, September 07, 2010 4:03 PM
    Moderator
  • So, may I ask.....I already have used this code to hide the Add existing button (and it works great). How would I revise the script to just change button name? In other words, would I need to add the whole code again, just don't put hideAddExistingButton line again, right?

    Can I not just keep my hide the add existing button code and add the IiElements line below the other? Does that make sense?


    Apps
    Tuesday, September 07, 2010 4:20 PM
  • Ok so you have used this function to hide 'add existing xxx button,

    1. Add this line to your code

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

                     else if (liElements[i].getAttribute(‘title’) == buttonTitles)
                            {
                                liElements[i].title='Change xxx button';

                                break;
                            }

    }

     

    2. call your function by passing title of new button

    let us know if you need any other informaiton


    Mahain : http://mahenderpal.wordpress.com
    Tuesday, September 07, 2010 4:42 PM
    Moderator
  • Hi, Mahender

    Well, I've been experiencing great difficulty. None of the codes listed (yours, Dave Hawes, Chandan) works to hide the 'Add Existing xxx button'. The only one that works for me is Daniel Cais - http://danielcai.blogspot.com/2010/03/mscrm-40-remove-existing-xxxxx-to-this.html.

    However, I have been unable to get a reply from him as to how to change 'New xxx' button label while still using his code (pretty much what you have been kind enough to try to explain above).

    Let's start from the beginning....I tried to put your hide 'Add Existing' code in my form's onload event but it does not work. The button still shows. I assume that your first line HideExistingButton(......) should include the actual 'id of the associated view and the relationship name that represents associated view'...not the actual button label (sorry, but this is all very new to me so excuse the obvious questions).

    thanks


    Apps
    Thursday, September 09, 2010 12:23 PM
  • surely you are not following instruction properly, ok leave it, let's talk about Daniel's solution, to replace your button title you have to replace below line 

    var btnId = '_MBtoplocAssocOneToMany' + grid.GetParameter('otc') + relName.replace(/_/g, "");   

    var btn = frameDoc.getElementById(btnId);   

    if (btn) {   

          //btn.parentNode.removeChild(btn);   

    btn.title="new title";

           }  

    remember to pick id of new button instead of 'Add existing button'

    Let us know !!


    Mahain : http://mahenderpal.wordpress.com
    Thursday, September 09, 2010 12:32 PM
    Moderator
  • Well, Daniel's code works perfectly for me (after I filled in the specifics)...so I MUST be doing something right.... :)

    That said, I will try your suggestion.

    Again, I appreciate your time and patience.

    I will let you know!


    Apps
    Thursday, September 09, 2010 5:09 PM
  • Question before I begin...I am simply revising the New button (along with removing the 'Add button'), therefore, why would I need to 'add pick id of new button instead of add existing button'?
    Apps
    Thursday, September 09, 2010 6:48 PM
  • you want to change title of new button right ?? not Add existing button ???


    Mahain : http://mahenderpal.wordpress.com
    Friday, September 10, 2010 4:16 AM
    Moderator
  • Yes.

    I will tell you where I am getting confused.

    In your example below...where do I add the id of new button?

    var btnId = '_MBtoplocAssocOneToMany' + grid.GetParameter('otc') + relName.replace(/_/g, "");   

    var btn = frameDoc.getElementById(btnId);   

    if (btn) {   

          //btn.parentNode.removeChild(btn);   

    btn.title="new title";

           }  


    Apps
    Friday, September 10, 2010 11:53 AM
  • Sorry I was not able to respond quickly enough on my blog post. 

    But here you are the code snippet based on what I have on my blog post. You may want to give it a try. 

    /**
     * Hide "Add Existing xxxxx button" in a CRM associated view.
     * @author Daniel Cai, http://danielcai.blogspot.com/
     *
     * Parameters:
     * @param navItemId: The navigation HTML element ID of the associated view.
          It usually starts with "nav".
     * @param relName: The relationship name that the associated view represents.
     */
     function hideAddExistingButton(navItemId, relName) {
     var clickActionPattern = /loadArea\(['"]{1}([A-Za-z0-9_]+)['"]{1}\).*/;
     var iframe;
    
     var renameNewButton = function() {
     debugger;
      var frameDoc = iframe.contentWindow.document;
      if (!frameDoc) return;
      
      var grid = frameDoc.all['crmGrid'];
      
      var btnId = '_MBlocAddRelatedToNonForm' + grid.GetParameter('otc') + crmForm.ObjectTypeCode + 'GUID';
      var btn = frameDoc.getElementById(btnId);
      if (btn) {
       btn.childNodes[0].childNodes[0].childNodes[1].innerText = btn.childNodes[0].childNodes[0].childNodes[1].innerText.replace(/New/, "Change");
      }  
     };
     
     var removeAddExistingButton = function() {
      var frameDoc = iframe.contentWindow.document;
      if (!frameDoc) return;
    
      var grid = frameDoc.all['crmGrid'];
    
      // Locate the "Add Existing" button using its magic id.
      var btnId = '_MBtoplocAssocOneToMany' + grid.GetParameter('otc') + relName.replace(/_/g, "");
      var btn = frameDoc.getElementById(btnId);
      if (btn) {
       btn.parentNode.removeChild(btn);
      }
     };
    
     var onReadyStateChange = function() {
      if (iframe.readyState === 'complete') {
       removeAddExistingButton();
       renameNewButton();
      }
     };
    
     (function init() {
      if (!crmForm.ObjectId) return;
    
      var navItem = document.getElementById(navItemId);
      if (!navItem) return;
    
      var clickAction = navItem.getAttributeNode('onclick').nodeValue;
      if (!clickAction || !clickActionPattern.test(clickAction))
       return;
    
      var areaId = clickAction.replace(clickActionPattern, '$1');
    
      navItem.onclick = function loadAreaOverride() {
       loadArea(areaId);
    
       iframe = document.getElementById(areaId + 'Frame');
       if (!iframe) return;
    
       iframe.attachEvent('onreadystatechange', onReadyStateChange);
      }
     })();
    }
    
    Hope it helps. 

     


    Daniel Cai | http://danielcai.blogspot.com
    Friday, September 10, 2010 2:38 PM
  • Hi, Daniel

    Thanks for your reply. I really appreciate it. I've been struggling although I have had other persons (Mahender, especially) trying to assist (which is appreciated).

    I put your code in and I got an error msg - an unhandled exception occurred in iexplore.exe...I

     clicked to debug and it sent me to the "var renameNewButton = function() {

    debugger;

    "var frameDoc = iframe.contentWindow.documents;....

    any ideas as to why?


    Apps
    Friday, September 10, 2010 3:13 PM
  • It worked fine for me (I just had another try on a different environment for a totally different form). Did you copy/paste the code correctly? 

    BTW, my code doesn't have a 's' after document

    You should remove debugger line as well, that's my debugging code. 


    Daniel Cai | http://danielcai.blogspot.com
    Friday, September 10, 2010 6:43 PM
  • worked. I took the debugger line out. (document line was OK...I just typed it with an 's' in the blog)

    THANK YOU!!!!!


    Apps
    • Split by DavidBerryMVP, Moderator Tuesday, November 23, 2010 10:32 PM Really deserves to be its own thread with separate answers
    • Merged by DavidBerryMVP, Moderator Tuesday, November 23, 2010 10:40 PM ok; I thought splitting this thread into two parts was going to be easy... but I failed... pasting it all back together
    Friday, September 10, 2010 8:03 PM
  • You are welcome, glad to know it helped. 

    Cheers,


    Daniel Cai | http://danielcai.blogspot.com
    Friday, September 10, 2010 8:27 PM
  • Hi, Daniel

    I need your assistance once again. I used your code above and it still works great. However, I need to also hide the Add Existing button in the associated view that is loaded into an IFRAME. I have unsuccessfully tried to combine your code for loading an associated view into an IFrame, hiding it from LHS navigation menu because I don't want to remove "Add Existing" button in the associated view, I want to simply hide it (as the code above works).

    Please help.

    Thanks


    Apps
    • Split by DavidBerryMVP, Moderator Tuesday, November 23, 2010 10:21 PM Really should be a separate thread replete with its own answers.
    • Merged by DavidBerryMVP, Moderator Tuesday, November 23, 2010 10:37 PM merging question back into split post
    Wednesday, November 17, 2010 7:14 PM
  • Hi, Daniel

    I hope that you can respond to my request for help below. Thank you


    Apps
    Friday, November 19, 2010 7:50 PM
  • Bernardina,

    See Dave Hawes' blog:  http://blog.davehawes.com/post/2008/04/24/MSCRM-4-Remove-Add-Existing-xxxxx-button.aspx

    You may be interested in the additional updates I've provided at the bottom of the comments.


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Friday, November 19, 2010 7:58 PM
    Moderator
  • Hi, Dave

    Thanks, so much, for responding to this. I will check out the site. I will post as to whether I was successful.

    Respectfully


    Apps
    Friday, November 19, 2010 8:04 PM
  • Did not work for me.

    Here is what I put on the OnLoad Event - besides the first line, where else would I need to add inhouse code? Thanks

    HideAssociatedViewButtons('nav_client_dml_status','client_dml_status');

    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;
                            }
                        }
                    }
                }
            }
        }
    }


    Apps
    Friday, November 19, 2010 8:29 PM
  • Since you've already established the view in an Iframe, your use of "HideAssociatedViewButtons" is incorrect.  Instead, directly call "HideViewButtons", and pass the Iframe element as the first parameter.  Example (and updated version of HideViewButtons that allows for partial button titles):

    function HideViewButtons(Iframe, buttonTitles) {
     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').substr(0, buttonTitles[j].length) == buttonTitles[j]) {
          liElements[i].style.display = 'none';
          break;
         }
        }
       }
      }
     }
     
     Iframe.attachEvent("onreadystatechange", HideTitledButtons);
    }
    
    HideViewButtons(crmForm.all.IFRAME_Something, new Array("Add existing"));
    


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Friday, November 19, 2010 8:52 PM
    Moderator
  • hi, dave

    adding that last code in worked great. I really struggled with this whole thing for days.

    I do need your assistance on one last thing, PLEASE. In addition to hiding the add existing button, I need to change the other button New Status to read Change Status.. How can I add this into the code that you have provided above (HideViewButtons).

    Thank you so much for your help. I really appreciate it. I have learned so much.


    Apps
    • Edited by Bernardina Sunday, November 21, 2010 6:25 PM wrote the wrong info
    Sunday, November 21, 2010 1:44 AM
  • Hi, Mahender

    I am still trying to figure out how to not only HideViewButton but I also need (at the same time) to change New Status button to read Change Status button. I took DBerry's and your code from above and tried to incorporate. However, this is not working. Can you look at it and tell me what I am doing wrong. Thanks. ASAP would be very appreciated.

    function HideViewButtons(Iframe, buttonTitles) {
     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').substr(0, buttonTitles[j].length) == buttonTitles[j]) {
          liElements[i].style.display = 'none';
          break;
          }
          else if (liElements[i].getAttribute(‘title’) == buttonTitles)
          {
          liElements[i].title='Change Status button';
          break;
         }
        }
       }
      }
     }
     
     Iframe.attachEvent("onreadystatechange", HideTitledButtons);
    }

    HideViewButtons(crmForm.all.IFRAME_CFLStatus, new Array("Add existing"));


    Apps
    Tuesday, November 23, 2010 4:35 PM
  • [UPDATE: this post has been changed to include updated code! ]

    The "title" attribute of the HTML element that represents the button is the text that appears when the mouse is hovered over the button.  While you'll probably want to replace that text as well, it will not change the text visible upon the button itself.

    Secondly, don't pervert the HideViewButtons function to do this work.  You may want to reuse that code elsewhere and could run into trouble with copy-and-paste.  Take your HideViewButtons function back to the one I last gave you, and use this new code to rename buttons instead:

     

    function RenameViewButtons(Iframe, origTitle, newName, newTitle) {
     function OnloadRename() {
     if (Iframe.readyState == 'complete') {
      function RenameTitledButtons(targetElement, origTitle, newName, newTitle) {
      var liElements = targetElement.getElementsByTagName('li');
    
      for (var i=0; i < liElements.length; i++) {
       if (liElements[i].getAttribute('title').substr(0, origTitle.length) == origTitle) {
       var labelSpan = liElements[i].childNodes[0];
    
       for (var j=0; j < labelSpan.childNodes[0].childNodes.length; j++) {
        if (labelSpan.childNodes[0].childNodes[j].nodeName == "SPAN") {
        var labelTextSpan = labelSpan.childNodes[0].childNodes[j];
    
        labelTextSpan.innerHTML = newName;
        break;
        }
       }
    
       liElements[i].title = newTitle;
       break;
       }
      }
      }
    
      RenameTitledButtons(Iframe.document, origTitle, newName, newTitle);
     }
     }
    
     Iframe.attachEvent("onreadystatechange", OnloadRename);
    }
    

     

    Then call it like so:

    RenameViewButtons(crmForm.all.IFRAME_CFLStatus, "Add a new", "Change Status", "Change the Status of this Record");
    



    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Tuesday, November 23, 2010 5:53 PM
    Moderator
  • I have added both your original code and this latest...unfortunately, it doesn't work.

    The Add Existing button is hidden. However, the new status did not change to 'Change Status'.

    Verification, please...The origTitle is the hover-over name of the New Status button; the newName = "Change Status"; newTitle should be the NEW hover-over name. Is this right?

    function HideViewButtons(Iframe, buttonTitles) {
     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').substr(0, buttonTitles[j].length) == buttonTitles[j]) {
          liElements[i].style.display = 'none';
          break;
         }
        }
       }
      }
     }
     
     Iframe.attachEvent("onreadystatechange", HideTitledButtons);
    }

    HideViewButtons(crmForm.all.IFRAME_CFLStatus, new Array("Add existing"));


    function RenameViewButtons(Iframe, origTitle, newName, newTitle) {
     function OnloadRename() {
     if (Iframe.readyState == 'complete') {
     RenameTitledButtons(Iframe.document, origTitle, newName, newTitle);
     }
     }

     Iframe.attachEvent("onreadystatechange", OnloadRename);
     }
    }
    RenameViewButtons(crmForm.all.IFRAME_CFLStatus, "Add a new status to this record", "Change Status", "Change the Status of this Record")

     


    Apps
    • Edited by Bernardina Wednesday, November 24, 2010 3:37 PM verification question
    Wednesday, November 24, 2010 2:45 PM
  • That's right.  Use the second "version" of the code that I posted.  I've deleted the first to reduce confusion.
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Wednesday, November 24, 2010 6:45 PM
    Moderator
  • Hi, Dave

    I replaced with your second version...however, the 'New Status' button still reads as "New Status"....should read 'Change Status'. Any ideas as to why I can't get this to work? Please help


    Apps
    Saturday, November 27, 2010 11:38 PM
  • Be sure to call the "RenameViewButtons" function before you set the "src" of the Iframe.  If you call it last, the code will not run, because it's tied to the "onreadystatechange" event which only fires as the contents of the Iframe is being loaded.  If you intend to rename the buttons after the content has been loaded (which is trickier to manage, because the contents load asynchronously, and therefore the most certain way to handle this is to attach to the "onreadystatechange" event), then you should use the "RenameTitledButtons" function; simply copy it out of "RenameViewButtons" in its entirety and place it alone in your code-space.  Again, I would recommend against it, because it's likely that the page may still be loading when the code executes.
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Sunday, November 28, 2010 6:18 PM
    Moderator
  • Ok... code update!  Apparently the wrong element was making its way into the code; after testing it myself, the new code works fine:

    function RenameViewButtons(Iframe, origTitle, newName, newTitle) {
     function OnloadRename() {
     if (Iframe.readyState == 'complete') {
     var iFrame = frames[window.event.srcElement.id];
     function RenameTitledButtons(targetElement, origTitle, newName, newTitle) {
     var liElements = targetElement.getElementsByTagName('li');
    debugger;
    
     for (var i=0; i < liElements.length; i++) {
      if (liElements[i].getAttribute('title').substr(0, origTitle.length) == origTitle) {
      var labelSpan = liElements[i].childNodes[0];
    
      for (var j=0; j < labelSpan.childNodes[0].childNodes.length; j++) {
      if (labelSpan.childNodes[0].childNodes[j].nodeName == "SPAN") {
      var labelTextSpan = labelSpan.childNodes[0].childNodes[j];
    
      labelTextSpan.innerHTML = newName;
      break;
      }
      }
    
      liElements[i].title = newTitle;
      break;
      }
     }
     }
    
     RenameTitledButtons(iFrame.document, origTitle, newName, newTitle);
     }
     }
    
     Iframe.attachEvent("onreadystatechange", OnloadRename);
    }
    
    
    


    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Sunday, November 28, 2010 7:13 PM
    Moderator
  • Works perfectly. Thanks for your continued support.
    Apps
    Monday, November 29, 2010 3:04 PM
  • Of interest may be the embedded "RenameTitledButtons" function, which allows you to rename any button or menu item throughout CRM (at least, in theory... because the HTML structures all appear identical, and the code makes concessions for the exceptions that I found).
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Monday, November 29, 2010 5:05 PM
    Moderator
  • I will further check out RenameTitledButtons function. I know there will be times that I will be asked to rename another button.


    Apps
    Monday, November 29, 2010 5:40 PM
  • I have posted my current code-set for the functionality to hide buttons , or to rename them , on my blog .  I've modified the code heavily from what I have posted here to make the code a little more modular.
    Dave Berry - MVP Dynamics CRM - http:\\crmentropy.blogspot.com
    Monday, November 29, 2010 9:46 PM
    Moderator