zoukankan      html  css  js  c++  java
  • Dyanmcis 365调用Action报Entity Reference cannot have Id and Key Attributes empty.错误

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

    我的Action中用了三个输出参数,都是EntityReference类型,用JavaScript或者实时工作流调用时候Action会报错:Entity Reference cannot have Id and Key Attributes empty.

    开始我以为是我的Custom Code Activity中的三个输出参数之一的值我使用的是 new EntityReference("logicalname", "Guid"); 这种方式赋值导致的。

    查了下这种方式赋值的话,这个输出参数EntityReference的 Name 的确没有值,于是我又额外给这个输出参数补充了Name属性的值还是报错。

    后来放弃了,将每个EntityReference类型的输出参数用两个文本类型的输出参数代替,一个是这个实体记录的ID,一个这个实体记录的主属性的值。

    这里需要值得注意,赋值给这种输出参数之前,需要先检查Custom Code Activity的EntityReference类型的输出参数的Name其他属性有值,如果没有值就拿来给其他输出参数赋值的话,会报Object reference not set to an instance of an object. 的错误。

    给其中为ID的文本输出参数赋值的时候如果赋值为Custom Code Activity的EntityReference类型的输出参数的实体显示名称相同的字段的话,会有问题,拿到的值是主属性的值。所以这个需要改成用Custom Code Activity的EntityReference类型的输出参数的记录URL(Dynamic),类似如下:

     记录URL类似如下:https://lydemo.crm.dynamics.com:443/main.aspx?etc=1&id=956d22c6-11de-e911-a82a-000d3a3b5c20&histKey=671294185&newWindow=true&pagetype=entityrecord

     用JavaScript调用后需要处理下这个输出文本来获取GUID的值,我用正则表达式来处理下就可以:

                                    var regex = /id=.{36}/;
                                    if (response.OutCountryId && response.OutCountryName) {
    
                                        formContext.getAttribute("ly_demo").setValue(
                                            [
                                                {
                                                    id: regex.exec(response.OutCountryId)[0].substring(3),
                                                    name: response.OutCountryName,
                                                    entityType: "ly_demofield"
                                                }
                                            ]
                                        );
                                    }
  • 相关阅读:
    Linux 期中架构 PHP
    Linux 期中架构 MySQL
    Python 示例 饮水记录
    Linux 期中架构 inotify
    Linux期中架构 全网备份案例
    分布式存储系统Ceph部署过程 · Jayden's Blog
    Go语言汇编器的设计
    linux基础3
    6.2.2 多余的列另起一行
    linux网络设备驱动2
  • 原文地址:https://www.cnblogs.com/luoyong0201/p/Dynamics_365_Entity_Reference_cannot_have_Id_and_Key_Attributes_empty.html
Copyright © 2011-2022 走看看