-1

I am trying to enable and disable the custom Ribbon button based on the form's subgrid values.I created a simple Java script method as a web resource and call it in Enable rule using workbench. below is my code:

function DisableSendInvitationRibbonButton()
{ 
   alert('test');
   var gridControl = document.getElementById("Attendees").control;

   if (gridControl.readyState != "complete") 
   {  alert('readyState not Complete');
      // delay one second and try again.  
      setTimeout(DisableSendInvitationRibbonButton, 100);
      return;
   }
   else
   {  alert('readyState Complete');
      var ids = gridControl.get_allRecordIds();
      alert(ids.length);
   }
}

The code is only hitting alert"Test", It looks like subgrid is not loading. Any help would be appreciated.

Thanks !

2 Answers2

0

Most probably you have some null var which you are not controlling try the code below to see where it is the problem

function DisableSendInvitationRibbonButton()
{ 
   alert('test');
   var myGrid = document.getElementById("Attendees");
   if(myGrid == null) {
       alert('myGrid is null');
       return;
   }
   var gridControl = myGrid.control;
   if(gridControl == null) {
       alert('gridControl is null');
       return;
   }
   if (gridControl.readyState != "complete") 
   {  alert('readyState not Complete');
      // delay one second and try again.  
      setTimeout(DisableSendInvitationRibbonButton, 100);
      return;
   }
   else
   {  alert('readyState Complete');
      var ids = gridControl.get_allRecordIds();
      alert(ids.length);
   }
}
AlexGreg
  • 838
  • 10
  • 22
0

Thanks all for your responses, I am able to solve this issue, the main thing that i noticed is that you must need to call Grid on change event and put all your logic there. below is my updated code:

function ShareMOM() 
{

    var subGridId = "ActionItems";

    var grid = document.getElementById(subGridId);

    if( grid != null)
      {
        var val = ReadSelectedSubGridRecords();
        return val;
      }
     else
      {
        return false;
      }
}


function ReadSelectedSubGridRecords()
 {
     if (document.getElementById('ActionItems'))
     {
         var grid = document.getElementById('ActionItems').control;
         var ids = grid.get_allRecords();

         if (ids.length > 0)
               {
                 return true;
               }  
          else
               {
                  return false;
                }

      }
}