locked
Hide Custom button on Order Form RRS feed

  • Question

  • Dear all,

    I have three custom button on my Order Form. On the bases of new_approvalStatus i want to show and hide button. new_approvalStatus have three status 1) Submit 2) Approve 3) Reject. Folling is my code and its giving me error of Object Required. Please help me in this regards.

     

     

    var myField = crmForm.all.new_approvalstatus.DataValue;

      //Get the current active HTML Element  
      var button1 = document.getElementById('ico_16_clone');  
      //Search the LI ( menuitem container ) Element  
     while( button1.tagName != 'LI' )
       button1 = button.parentElement;         


      //Get the current active HTML Element  
      var button2 = document.getElementById('ico_16_remove');  
      //Search the LI ( menuitem container ) Element  
     while( button2.tagName != 'LI' )
       button2 = button.parentElement;         


      //Get the current active HTML Element  
      var button3 = document.getElementById('ico_16_1011');  
      //Search the LI ( menuitem container ) Element  
     while( button3.tagName != 'LI' )
       button3 = button.parentElement;    

    if(myField ==1)
    {
    button2.style.display='none';
    button3.style.display='none';

    }

    if(myField ==2)
    {
    button1.style.display='none';
    button2.style.display='none';
    button3.style.display='none';
    }
    if(myField ==3)
    {
    button2.style.display='none';
    button3.style.display='none';
    }


    Project Manage - Microsoft Dynamics
    Thursday, August 26, 2010 8:32 AM

Answers

  • There is easier solution. Try to use following code:

    var lis = document.getElementsByTagName('LI');
    var i = 0;
    while (i < lis.length)
    {
      if (lis[i].getAttribute('title') == '<<Your Title>>')
      {
       lis[i].outerHTML = '';
      }
      i = i + 1;
    }


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    • Marked as answer by Jim Glass Jr Thursday, August 26, 2010 4:08 PM
    Thursday, August 26, 2010 3:54 PM
    Moderator

All replies

  • For custom buttons buttonid will be generated at runtime. Since the buttonid 'ico_16_clone', 'ico_16_remove', 'ico_16_1011' does not exist each and every time Object required error is thrown.

    Use the below code to obtain the button id and disable it. Provide button tool tip to find button id.

    var lis = document.getElementsByTagName('LI');
    var i = 0;
    while (i < lis.length)
    {
      if (lis[i].getAttribute('title') == '<<Your Title>>')
      {
       lis[i].style.display="none";
      }
      i = i + 1;
    }

    Thursday, August 26, 2010 8:47 AM
  • Thanks the code works but there is a little proble. When I am open the order its is not showing that botton .... its ok till that stage .... but when I miximixe that window it show me again. What can i do.

     


    Project Manage - Microsoft Dynamics
    Thursday, August 26, 2010 9:37 AM
  • Try to use window.onresize event on form load

    window.attachEvent('onresize', FunctionToHideButtons);


    Mahain : http://mahenderpal.wordpress.com
    Thursday, August 26, 2010 9:41 AM
    Moderator
  • Use window.onresize event by setting this in your onload.

    window.attachEvent('onresize', theHideButton);

    function theHideButton()
    {
    // Place button hiding code inside hefunction
    }

    Thursday, August 26, 2010 9:42 AM
  • its works... but after maximizing when i minimize that window again It show me that button again :)
    Project Manage - Microsoft Dynamics
    Thursday, August 26, 2010 10:45 AM
  • Can you post your entire code here?
    Thursday, August 26, 2010 11:00 AM
  • here it is....

    window.attachEvent('onresize',checkStatusandHide);
    checkStatusandHide();
    function checkStatusandHide()
    {
    var myField = crmForm.all.new_approvalstatus.DataValue;

    if(myField ==1)
    {
    theHideButtonSubmit()
    }
    if(myField ==2)
    {
    theHideButtonSubmit()
    theHideButtonApprove()
    theHideButtonReject()
    }
    if(myField ==3)
    {
    theHideButtonApprove()
    theHideButtonReject()
    }
    if(myField ==4)
    {
    theHideButtonApprove()
    theHideButtonReject()
    }
    }
    //Submit Button Function
    function theHideButtonSubmit()
    {
    var lis = document.getElementsByTagName('LI');
    var i = 0;
    while (i < lis.length)
    {
      if (lis[i].getAttribute('title') == 'Submits Order to logistics department for Order Processing')
      {
       lis[i].style.display="none";
      }
      i = i + 1;
    }
    }

    //Approve Button Function
    function theHideButtonApprove()
    {
    var lis = document.getElementsByTagName('LI');
    var i = 0;
    while (i < lis.length)
    {
      if (lis[i].getAttribute('title') == 'Submits to Manager for Approval')
      {
       lis[i].style.display="none";
      }
      i = i + 1;
    }
    }
    //Reject Button Function
    function theHideButtonReject()
    {
    var lis = document.getElementsByTagName('LI');
    var i = 0;
    while (i < lis.length)
    {
      if (lis[i].getAttribute('title') == 'Reject Order')
      {
       lis[i].style.display="none";
      }
      i = i + 1;
    }
    }


    Project Manage - Microsoft Dynamics
    Thursday, August 26, 2010 11:12 AM
  • There is easier solution. Try to use following code:

    var lis = document.getElementsByTagName('LI');
    var i = 0;
    while (i < lis.length)
    {
      if (lis[i].getAttribute('title') == '<<Your Title>>')
      {
       lis[i].outerHTML = '';
      }
      i = i + 1;
    }


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    • Marked as answer by Jim Glass Jr Thursday, August 26, 2010 4:08 PM
    Thursday, August 26, 2010 3:54 PM
    Moderator