Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Plugins Dynamics CRM 2011错误-设置实体引用的值时,不能将parentid设置为null_Plugins_Dynamics Crm 2011_Dynamics Crm_Dynamics Crm Online - Fatal编程技术网

Plugins Dynamics CRM 2011错误-设置实体引用的值时,不能将parentid设置为null

Plugins Dynamics CRM 2011错误-设置实体引用的值时,不能将parentid设置为null,plugins,dynamics-crm-2011,dynamics-crm,dynamics-crm-online,Plugins,Dynamics Crm 2011,Dynamics Crm,Dynamics Crm Online,我想写一个Dynamics CRM 2011(在线)插件,它获取联系人实体的地址并从中创建customeraddress实体。它基本上应该采用地址号为1的customeraddress,并从中创建一个地址号为3的新的相同customeraddress。新创建的customeraddress的父级应为联系人 为此,我编写了以下插件: 名称空间插件 { 使用制度; 使用System.Linq; 使用System.ServiceModel; 使用Microsoft.Xrm.Sdk; 使用插件。实体;

我想写一个Dynamics CRM 2011(在线)插件,它获取联系人实体的地址并从中创建customeraddress实体。它基本上应该采用地址号为1的customeraddress,并从中创建一个地址号为3的新的相同customeraddress。新创建的customeraddress的父级应为联系人

为此,我编写了以下插件:

名称空间插件
{
使用制度;
使用System.Linq;
使用System.ServiceModel;
使用Microsoft.Xrm.Sdk;
使用插件。实体;
使用Microsoft.Xrm.Sdk.Query;
使用System.Collections.Generic;
/// 
///AddressMover插件。
///     
公共类AddressMoverPlugin:插件
{
/// 
///初始化类的新实例。
/// 
公共地址moverplugin()
:base(typeof(AddressMoverPlugin))
{
Add(新元组(20,“更新”,“联系”,新操作(ExecuteAddressMoverPlugin));
}
/// 
///执行插件。
/// 
///包含
/// ,
/// 
///及
/// 
受保护的void executedDressMoverPlugin(LocalPluginContext localContext)
{
if(localContext==null)
{
抛出新ArgumentNullException(“localContext”);
}
//提取跟踪服务以用于调试沙盒插件。
ITracingService tracingService=localContext.tracingService;
//从服务提供程序获取执行上下文。
IPluginExecutionContext context=localContext.PluginExecutionContext;
IOOrganizationService=localContext.OrganizationService;
实体实体=上下文。输入参数[“目标”]作为实体;
if(实体包含(“地址1_行1”))
{
var newAddress=新实体(“customeraddress”);
newAddress.Attributes[“name”]=“business”;
//有关类型代码的详细信息可在此处找到:http://msdn.microsoft.com/en-us/library/aa682922.aspx
属性[“objecttypecode”]=2;
//newAddress.Attributes[“addresstypecode”]=“其他”;
newAddress.Attributes[“parentid”]=entity.Id;
tracingService.Trace(“父id为:+newAddress[“parentid]”);
newAddress.Attributes[“addressnumber”]=3;
如果(实体包含(“地址1_行1”))新地址[“行1”]=实体[“地址1_行1”];
如果(实体包含(“地址1_行2”))新地址[“行2”]=实体[“地址1_行2”];
如果(实体包含(“地址1_行3”))新地址[“行3”]=实体[“地址1_行3”];
如果(实体包含(“地址1_市”))新地址[“城市”]=实体[“地址1_市”];
如果(实体包含(“地址1_州或省”))新地址[“地址或省”]=实体[“地址1_州或省”];
如果(实体包含(“地址1_postalcode”))新地址[“postalcode”]=实体[“地址1_postalcode”];
如果(实体包含(“地址1_国家”))新地址[“国家”]=实体[“地址1_国家”];
创建(新地址);
//抛出新异常(“开始跟踪”);
}
}
}
}
请注意这一行:

                tracingService.Trace("parent id is: " + newAddress["parentid"]);
执行此操作时,会收到一条错误消息,指出未设置parentid:

未处理的异常:System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault,Microsoft.Xrm.Sdk,Version=5.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35]:属性:parentid不能设置为NULLDetail:
-2147220989
属性:不能将parentid设置为NULL
2013-09-05T10:42:46.0285782Z
[插件:Plugins.AddressMoverPlugin]
[2d6c4656-6815-e311-a90e-ac162dbe3ffe:AddressMoverPlugin]
输入Plugins.AddressMoverPlugin.Execute(),相关Id:65dc4a08-1075-4340-83a5-d35464375348,启动用户:1d55dd88-f2f8-e211-a305-ac162db64ac6
Plugins.AddressMoverPlugin正在为实体触发:联系人,消息:更新,相关Id:65dc4a08-1075-4340-83a5-d35464375348,启动用户:1d55dd88-f2f8-e211-a305-ac162db64ac6
父id为:b6eb3f86-1716-e311-aa0d-ac162dbe3218
异常:System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]:属性:parentid不能设置为NULL(故障详细信息等于Microsoft.Xrm.Sdk.OrganizationServiceFault),关联Id:65dc4a08-1075-4340-83a5-d35464375348,启动用户:1d55dd88-f2f8-e211-a305-ac162db64ac6
正在退出Plugins.AddressMoverPlugin.Execute(),相关Id:65dc4a08-1075-4340-83a5-d35464375348,启动用户:1d55dd88-f2f8-e211-a305-ac162db64ac6
跟踪显然包含来自代码的输出,该代码表示已设置parentid字段:

parent id is: b6eb3f86-1716-e311-aa0d-ac162dbe3218

为什么我会收到这样一条错误消息,说父id为null,而不是null?我怎样才能避免呢?这是由于Dynamics CRM中cutomeraddress实体的特殊行为造成的吗?

父ID
实体引用

如果是,请尝试以下操作:

EntityReference parentRef=new EntityReference();
parentRef.Id=entity.Id;
parentRef.EntityLogicalName=“联系人”;
属性[“parentid”]=parentRef;
我希望它能起作用