zoukankan      html  css  js  c++  java
  • Dynamics 365中的快速创建窗体获取父记录信息

    我是微软Dynamics 365 & Power Platform方面的工程师罗勇,也是2015年7月到2018年6月连续三年Dynamics CRM/Business Solutions方面的微软最有价值专家(Microsoft MVP),欢迎关注我的微信公众号 MSFTDynamics365erLuoYong ,回复400或者20200407可方便获取本文,同时可以在第一间得到我发布的最新博文信息,follow me!

    Dynamics 365的快速创建窗体可以在当前页面中新建记录,而不是打开新页面,很多时候该功能比较方便,当然实体需要启用快速创建功能,并且创建至少一个类型为快速创建(Quick Create)的窗体,还有值得注意的就是这个快速创建窗体需要添加到需要使用的App中才行(在App的编辑模式下将该表单加入后发布即可),否则就没有办法使用快速创建功能,会使用普通的创建功能。

     有时候快速表单中需要获取父记录的信息,目前我认为是没有办法直接获取到父记录所在窗体的上下文信息来获取字段值的。

    但是也有其他办法,比如根据父记录的ID和实体逻辑名称查询下。

    如何获取父记录的信息,这里有两种方法。

    方法一:将关联到父记录的字段放到快速创建窗体中,一般不需要显示,设置为默认隐藏即可。然后在代码中可以获取到该字段的值,执行查询即可。我这里提供些示例代码:

        onLoad: function (executionContext) {
            var formContext = executionContext.getFormContext();
            if (formContext.ui.getFormType() === 1) {
                var parentid = formContext.getAttribute("lvo_parentid").getValue();
                if (parentid) {
                    Xrm.WebApi.retrieveRecord(parentid[0].entityType, parentid[0].id, "?$select=_ly_requesttype_value").then(
                        function success(result) {
                            if (result._ly_requesttype_value.toLowerCase() === "6f45cd2f-8f4e-ea11-a812-000d3a378f47")) {
                                formContext.getControl("ly_customfield").setVisible(true);
                            }
                        },
                        function (error) {
                            Xrm.Navigation.openErrorDialog({ message: "Error:" + error.message });
                        }
                    );
                }
            }
        }

    方法二,通过 getPageContext (Client API reference) 。在快速创建窗体的OnLoad事件执行代码中,通过 Xrm.Utility.getPageContext().input.createFromEntity 获取到是从哪个父记录来创建子记录的,然后执行一次查询即可。官方文档说明如下:

    Syntax

    Xrm.Utility.getPageContext();

    Returns

    The method returns an object with the input property. The input property is an object with the following attributes depending on whether you are currently on the entity form or entity list:

    Entity form

    NameTypeDescription
    pageType String The current page type. The value returned is "entityrecord".
    entityName String Logical name of the entity currently displayed.
    entityId String ID of the entity record currently displayed in the form.
    createFromEntity Lookup The parent record that provides default values based on mapped attribute values. The lookup object has the following String properties: entityTypeid, and name.
    formId String ID of the currently displayed form.
  • 相关阅读:
    leetcode 75 颜色分类 A
    leetcode525连续数组 A
    WCF无身份验证配置
    三读设计模式
    EntityFrameWork+Oracle学习笔记搭配环境(一)
    EntityFrameWork+Oracle学习笔记DBfirst(二)
    用Python解答百度测试开发算法面试题
    Python实现采集wordpress整站数据的爬虫
    吾八哥学Python(六):运算符与表达式
    吾八哥学Python(四):了解Python基础语法(下)
  • 原文地址:https://www.cnblogs.com/luoyong0201/p/Dynamics_365_Quick_Create_Form_Retrieve_Parent_Record_Info.html
Copyright © 2011-2022 走看看