CRM 2011功能区自定义按钮可见性控制

时间:2014-09-02 14:04:01

标签: javascript button dynamics-crm-2011 crm subgrid

我正在尝试根据表单的子网格值启用和禁用自定义功能区按钮。我创建了一个简单的Java脚本方法作为Web资源,并在使用工作台启用规则中调用它。下面是我的代码:

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

代码只是点击警告“测试”,看起来像子网格没有加载。 任何帮助将不胜感激。

谢谢!

2 个答案:

答案 0 :(得分:0)

最有可能你有一些你无法控制的null var尝试下面的代码来看看它是什么问题

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

答案 1 :(得分:0)

感谢大家的回复,我能够解决这个问题,我注意到的主要事情是你必须在变更事件上调用Grid并将所有逻辑放在那里。下面是我更新的代码:

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

      }
}