首页 > 解决方案 > Xrm.Navigation.openForm 自动从前一个表单设置查找字段

问题描述

我在“Parcours”表单中添加了一个新按钮,该按钮将我带到另一个表单“问题”,其中包含Xrm.Navigation.openForm

在此处输入图像描述

“问题”表单有一个来自“Parcours”的查找字段,我想从以前的表单中自动填充它,例如:

在此处输入图像描述

这是我的按钮代码,我想自动检测 parcours 的 ID 并将其设置为新的“问题”表单

function NavigateQuestion(){
    var entityFormOptions = {};
entityFormOptions["entityName"] = "zs_question";
var formParameters = {};

// Set lookup column
formParameters["zs_parcours"] = ""; // I want to put the ID here from the previous form.
formParameters["zs_parcoursname"] = ""; // Name of the parcours.
formParameters["zs_parcourstype"] = "zs_parcours"; // Table name. 

Xrm.Navigation.openForm(entityFormOptions, formParameters).then(
    function (success) {
        console.log(success);
        console.log(formParameters);
    },
    function (error) {
        console.log(error);
    });


}

标签: javascriptdynamics-crmpowerappsxrm

解决方案


您应该能够从当前记录表单本身获取值并进行分配。

确保为最新的客户端 API 方法传递 formContext(我将语法放在注释代码部分)。

// Set lookup column
formParameters["zs_parcours"] = Xrm.Page.data.entity.getId(); // or by using form context -- formContext.data.entity.getId();
formParameters["zs_parcoursname"] = Xrm.Page.getAttribute("zs_name").getValue(); // or by using form context -- formContext.getAttribute("zs_name").getValue();
formParameters["zs_parcourstype"] = "zs_parcours"; 

推荐阅读