有时要根据主表的审批状态来控制子表上的按钮要不要显示,比如我们有一个需求审批通过后就不能再上传文件了。
首先打开Visual Ribbon Editor,
如下图,我们可以利用Enable Rules –> CustomRule 用js来控制按钮是否显示:
js function:
首先用odata取出主表的状态,然后根据主表的状态来判断是否显示:
var approvalStatus = null;
function controlUpload(){
var marketingPlan = Xrm.Page.getAttribute("new_marketing_planid").getValue();
if (marketingPlan != null) {
var filter = "new_marketing_planSet?$select=new_approval_status,new_monthid&$filter=new_marketing_planId eq guid'" + marketingPlan[0].id + "'";
var result = Query_ent(filter);
if (result != null && result.new_approval_status != null) {
approvalStatus = result.new_approval_status
}
}
if (approvalStatus != null && (approvalStatus.Value == 2 || approvalStatus.Value == 3)) {
return false;
}
else {
return true;
}
}