繁体   English   中英

Microsoft Dynamics CRM 2011/2013年

[英]Microsoft Dynamics CRM 2011/2013

在我的实体(A)中设置了50个选项。 如果用户选择10个选项设置值而未选择剩余的一个选项设置值,则他/她单击“保存”按钮。 在这种情况下,我需要提醒用户“填写所有选项集”。 我不想单独获取选项集的架构名称,我需要动态获取所有选项集的架构名称。

可能吗? 帮我。

我尚未测试此功能,但是您可以尝试此功能并根据需要进行更改。

function IsFormValidForSaving(){
var valid = true;
var message = "Following fields are required fields: \n";

    Xrm.Page.data.entity.attributes.forEach(function (attribute, index) {
        if (attribute.getRequiredLevel() == "required") {
            if(attribute.getValue() == null){

                var control = attribute.controls.get(0);

                // Cheking if Control is an optionset and it is not hidden
                if(control.getControlType() == "optionset" && control.getVisible() == true) {
                    message += control.getLabel() + "\n";
                }

                valid = false; 
            }
        }
    });

    if(valid == false)
    {
        alert(message);
    }
}

参考: Microsoft Dynamics CRM 2011验证所需的表单javascript

在保存事件之前,必填字段会单独发出警报。 如果您希望针对所有未填充的选项集阻止单个警报例程,则需要删除需求约束并自己管理约束(可能在保存处理程序中)。 我只是在这里写这个想法(未经测试)。

// enter all optionsets ids
var OptionSets50 = ["new_optionset1","new_optionset2","new_optionset50"];     
var dirtyOptions  = [];

function MyOptionSet(id) {
   var mos  = this;
   var Obj = Xrm.Page.getAttribute(id);
   var Ctl = Xrm.Page.getControl(id);

   Obj.addOnChange(
    function () {
        if (Obj.getValue() != null)
             delete dirtyOptions[id];       
        else 
             dirtyOptions[id] = mos;
   });

   this.GetLabel = function() {
      return Ctl.getLabel();
   }

   if (Obj.getValue() == null) 
       dirtyOptions[id] = mos;
}

function OnCrmPageLoad() { 
   for(var x in OptionSets50) {
       OptionSets50 [x] = new MyOptionSet(OptionSets50 [x]);
   }

   Xrm.Page.data.entity.addOnSave(OnCrmPageSave);
}

//check for dirty options and alert 
function OnCrmPageSave(execContext) {
   var sMsg = "The following Optinsets Are Required: ";
   var sLen = sMsg.length;
   for(var os in dirtyOptions) {
       sMsg += dirtyOptions[os].GetLabel() + "\n";
   }

   if (sMsg.length > sLen) {
       execContext.getEventArgs().preventDefault();
       alert(sMsg);
   }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM