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



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

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

代码只点击了警报"测试",看起来子网格没有加载。如有任何帮助,我们将不胜感激。

谢谢!

很可能您有一些空的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);
   }
}

感谢大家的回复,我能够解决这个问题,我注意到的主要问题是,您必须在更改事件时调用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;
                }
      }
}

相关内容

  • 没有找到相关文章

最新更新