C# 当帐户更新时,如何获取联系人的参考id联系人也应更新 if(entity.LogicalName==“账户”) { 实体帐户=(实体)服务.Retrieve(context.PrimaryEntityName,context.PrimaryEntityId,newcolumnset(true)); tracingService.Trace(“1”); Guid ContactGuid=Account.Id; tracingService.Trace(“9”); //抛出新异常(“联系人guid”+联系人guid); 实体objContact=(实体)服务.Retrieve(“contact”,((EntityReference)Account.Attributes[“new_Account”]).Id,new ColumnSet(true)); tracingService.Trace(“2”); 字符串Updatename=Account.GetAttributeValue(“名称”); tracingService.Trace(“3”); objContact.Attributes[“fullname”]=Updatename; tracingService.Trace(“4”); 字符串Updateemail=Account.GetAttributeValue(“emailaddress1”); tracingService.Trace(“5”); objContact.Attributes[“emailaddress1”]=Updateemail; tracingService.Trace(“6”); 字符串Updateaddress=Account.GetAttributeValue(“address1_复合”); tracingService.Trace(“7”); objContact.Attributes[“address1_composite”]=Updateaddress; 服务更新(objContact); }
假设您想要获取帐户的主要联系人的ID:C# 当帐户更新时,如何获取联系人的参考id联系人也应更新 if(entity.LogicalName==“账户”) { 实体帐户=(实体)服务.Retrieve(context.PrimaryEntityName,context.PrimaryEntityId,newcolumnset(true)); tracingService.Trace(“1”); Guid ContactGuid=Account.Id; tracingService.Trace(“9”); //抛出新异常(“联系人guid”+联系人guid); 实体objContact=(实体)服务.Retrieve(“contact”,((EntityReference)Account.Attributes[“new_Account”]).Id,new ColumnSet(true)); tracingService.Trace(“2”); 字符串Updatename=Account.GetAttributeValue(“名称”); tracingService.Trace(“3”); objContact.Attributes[“fullname”]=Updatename; tracingService.Trace(“4”); 字符串Updateemail=Account.GetAttributeValue(“emailaddress1”); tracingService.Trace(“5”); objContact.Attributes[“emailaddress1”]=Updateemail; tracingService.Trace(“6”); 字符串Updateaddress=Account.GetAttributeValue(“address1_复合”); tracingService.Trace(“7”); objContact.Attributes[“address1_composite”]=Updateaddress; 服务更新(objContact); },c#,dynamics-crm,C#,Dynamics Crm,假设您想要获取帐户的主要联系人的ID: if (entity.LogicalName == "account") { Entity Account = (Entity)service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet(true)); tracingService.Trace("1");
if (entity.LogicalName == "account")
{
Entity Account = (Entity)service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet(true));
tracingService.Trace("1");
Guid ContactGuid = Account.Id;
tracingService.Trace("9");
//throw new Exception("Contact guid" + ContactGuid);
Entity objContact = (Entity)service.Retrieve("contact", ((EntityReference)Account.Attributes["new_account"]).Id, new ColumnSet(true));
tracingService.Trace("2");
string Updatename = Account.GetAttributeValue<string>("name");
tracingService.Trace("3");
objContact.Attributes["fullname"] = Updatename;
tracingService.Trace("4");
string Updateemail = Account.GetAttributeValue<string>("emailaddress1");
tracingService.Trace("5");
objContact.Attributes["emailaddress1"] = Updateemail;
tracingService.Trace("6");
string Updateaddress = Account.GetAttributeValue<string>("address1_composite");
tracingService.Trace("7");
objContact.Attributes["address1_composite"] = Updateaddress;
service.Update(objContact);
}
EntityReference primaryContact=Account.GetAttributeValue(“primarycontactid”);
Guid contactGuid=primaryContact.Id;
请注意,该帐户的所有联系人的关系
contact\u customer\u accounts
为1:N,因此您需要从该关系中检索这些联系人并对其进行循环。请详细描述您的问题。在目前的状态下,你的意思是完全不清楚的。我正在尝试在帐户更新和联系人应该更新时创建联系人记录。。。。
EntityReference primaryContact = Account.GetAttributeValue<EntityReference>("primarycontactid");
Guid contactGuid = primaryContact.Id;