有没有办法将 Dynamics CRM 中的字段设为一次性输入字段?

Is there a way to make a field in Dynamics CRM as one time entry field?

基本上,我想要的是用户应该能够 select 下拉列表,并且在制作并保存 selection 后不能更改它。所以它将是一个一次性输入字段。

下面是我要应用此字段的屏幕截图属性。

所以这个字段有 select离子。为了使业务逻辑免于失败,我必须将其设为一次性输入字段。

我在表单编辑器中查找了可能的东西,但找不到任何能让我实现这一点的东西。

更新 #1

下面是我的onload函数:

function Form_onload() {
    var formType = Xrm.Page.ui.getFormType();
    var p = Xrm.Page.getAttribute("opportunityid");
--------------NEW CODE--------------------------------

    if(formType ==2){ //form type 2 means the form is a saved form. form type 1 is new form.

    alert(formType);
    var myattribute = Xrm.Page.getAttribute("var_internal");
    var myname = myattribute.getName();
    if (Xrm.Page.getControl(myname) != null) {
        //alert(myname);
        Xrm.Page.getControl(myname).setDisabled(true);
    }
    }
--------------NEW CODE---------------------------
    if (formType == 1 && p != null && p.getValue() != null) {
        alert('Child Opportunities can only be created by clicking the Create Child Opportunity button in the Opportunity ribbon.');
        window.top.close();
    }


}

此类自定义需求没有OOB配置,但我们可以应用一些脚本逻辑。

假设这是一个选择列表,默认为null,而不是双选项布尔字段,我们可以使用onLoad表单脚本来检查它是否有值并锁定它。不需要 onChange 功能。

如果是bool字段,那就很难实现了。您必须跟踪初始值和为实现所需逻辑所做的更改。或者通过一些 unsupported code.

无代码解决方案:我认为您可以使用带有 Yes/No 选项和默认未分配值的选项集。然后将该字段添加到 Field Level Security,并将 "Allow Update" 设置为 No.

更新 FLS 字段权限时,确保配置文件与组织相关联 "team" 以便所有用户都可以看到该字段:

Arun 已经给了你如何继续的提示,我刚刚在我的一个实例上尝试了这个请求。

在我的案例中创建一个额外的字段(虚拟字段),我称之为 new_hasfieldbeenchanged1 当字段更改时,该字段将保存数据。锁定此字段(始终)并将此字段保留在表单上(但可见 =false)

现在您需要 2 个触发器 Onload 和 OnSave。下面的函数将完成你的工作。让我知道这是否有帮助。

function onLoad(executionContext) {

    debugger;
    var formContext;
    if (executionContext && executionContext.getFormContext()) {
        formContext = executionContext.getFormContext();
        //executionContext.getEventSource()
        if (formContext.getAttribute("new_hasfieldbeenchanged1") && formContext.getAttribute("new_hasfieldbeenchanged1").getValue()!=null) {
            if (formContext.getControl("new_twooptionfield")) {
                formContext.getControl("new_twooptionfield").setDisabled(true);
            }
        }
    }
}
function onSave(executionContext) {
    debugger;
    var formContext;
    if (executionContext && executionContext.getFormContext()) {
        formContext = executionContext.getFormContext();
        //executionContext.getEventSource()
        if(formContext.getAttribute("new_hasfieldbeenchanged1") && formContext.getAttribute("new_twooptionfield") && formContext.getAttribute("new_twooptionfield").getIsDirty()){
            formContext.getAttribute("new_hasfieldbeenchanged1").setValue((new Date()).toString());
            if (formContext.getControl("new_twooptionfield")) {
                formContext.getControl("new_twooptionfield").setDisabled(true);
            }
        }

    }
}

由于我的 DEV 中的环境特定设置,我无法重现 @Eccountable 建议的内容。虽然,他的解决方案在其他环境中有效。

@AnkUser 也有一个很好的答案,但我希望缩短代码并使事情尽可能简单。

我的解决方案

我能够在 客户端使用 Javascript 来处理这个问题。 使用 XRM 工具箱。

在 XRM 工具箱中,我找到了机会的 javascript,并在机会为 New 和机会为 formType 时观察了字段变化现有。此变量 (formType) 在机会为新时为 =1,在机会为 Existing/Saved.

时为 =2

使用这条信息,我能够在 Form_onload()

中如下利用我的 Javascript
function Form_onload() {
    if (formType == 2) {
        var myattribute = Xrm.Page.getAttribute("internal");
        var myname = myattribute.getName();
        if (Xrm.Page.getControl(myname) != null) {
            Xrm.Page.getControl(myname).setDisabled(true);
        }
    }
}