javascriptdynamics-crmdynamics-crm-365crm-ribbon-workbench

Button on record is not hidden but can't be clicked, xrm workbench


So I added rule on button in record subgrid, so when condition is met it will return false and supposedly hide the button. The script is working but instead of hiding the button, it make the button disabled (can't be clicked). Am I missing something? Never used xrm ribbon workbench before.

Here is my script below:

function validatebuttondelete()
{
  var entityName = Xrm.Page.data.entity.getEntityName();

  if(entityName == "msdyn_workorder")
  {
    if(Xrm.Page.ui.getFormType() != 1)
    {
       var received = Xrm.Page.getAttribute("mjt_received").getValue()
       var receivedSp = Xrm.Page.getAttribute("mjt_received_sp").getValue()
       var stageName = Xrm.Page.data.process.getActiveStage().getName();

       if(stageName == "Branch")
       {
         if(received == 0)
         {
           return false;
         }
         else
         {
           return true;
         }
       }

       if(stageName == "Service Point")
       {
         if(receivedSp == 0)
         {
           return false;
         }
         else
         {
           return true;
         }
       }
     }
   }
}

enter image description here


Solution

  • You can read about Enable rule & Display rule here.

    To hide the delete button (trash can/dustbin icon) in subgrid completely - you can simply right click & “Hide” it. Read more

    But your requirement is little more complex. Has to be hidden based on some rule. Atleast for you it was disabled. Many people tried that & finally ended up in simple alert message as the button didn’t cooperate.

    Reference

    the (missing: Enable rule) did not hide the delete button, but allowed us to prevent the Delete action for the disabled records. We went ahead and unhid the Delete button, and then selected the Customize Command option. This populated the Mscrm.DeleteSelectedRecord command under the Command in Ribbon Workbench. We added another Enable rule called RestrictDeleteFromSubgrid