简体   繁体   English

如何填充相关查找字段CRM 2011

[英]How to populate related lookup field CRM 2011

I want to create an auditing plugin that whenever a "contact" entity is changed, a "historical contact" entity is created that had all the data of the old "contact" entity before the change. 我想创建一个审计插件,无论何时更改“联系人”实体,都将创建一个“历史联系人”实体,该实体具有更改前的旧“联系人”实体的所有数据。

My question is, if I have a lookup field in "contact" to "accounts", how do I get this lookup to the specific "account" and place it in the lookup field for the "historical contact" entity? 我的问题是,如果我在“联系人”到“帐户”中有一个查找字段,如何将查找到特定的“帐户”并将其放在“历史联系人”实体的查找字段中?


I completed the plugin, but now there is a new issue. 我完成了插件,但是现在有一个新问题。

The "contact" entity can have a blank in the "first name" field. “联系人”实体的“名字”字段中可以为空白。

The "historical contact" entity has "first name" as its primary field, although it is not required. 尽管不需要,“历史联系人”实体将“名字”作为其主要字段。

If there is no "first name" when creating "historical contact" entity it throws an error. 如果在创建“历史联系人”实体时没有“名字”,则会引发错误。 I do not know why this is. 我不知道为什么会这样。

Do I need a primary field to create an entity even if the field is labeled to have "no constraint"? 即使该字段被标记为“无约束”,我也需要一个主字段来创建实体吗?

I'm not sure I follow. 我不确定是否要遵循。 You're creating a full copy of a contact when something changes? 您正在创建联系人的完整副本吗? To do that is be quite simple with a Pre Image on the Post Execute of Update message. 要做到这一点非常简单,只需在更新执行后消息上显示一个前映像即可。 The Pre Image is a snapshot of the contact before the update. Pre Image是更新之前联系人的快照。

But why aren't you using the provided Auditing functionality? 但是,为什么不使用提供的审核功能呢?

You have two options: 您有两种选择:

1) create a plugin along the lines of the following: 1)按照以下步骤创建一个插件:

public void Execute(IServiceProvider serviceProvider)
{
    var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    var service = ((IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory))).CreateOrganizationService(context.UserId);

    var originalContact = context.InputParameters["Target"] as Entity;
    var newContact = new Entity("new_historicalcontact");
    if (originalContact.Contains("firstname"))
    {
        newContact.Add("new_firstname", orginalContact["firstname"]);
    }
    if (originalContact.Contains("emailaddress1"))
    {
        newContact.Add("new_emailaddress1", orginalContact["emailaddress1"]);
    }
    if (originalContact.Contains("parentcustomerid"))
    {
        newContact.Add("new_parentcustomerid", orginalContact["parentcustomerid"]);
    }

    //etc etc for other properties
    service.Create(newContact);
}

if you aren't familiar with plugins, there are plenty of tutorials around, you can start with something like the recommendation I gave in this question 如果您不熟悉插件,那么这里有很多教程,您可以从我在此问题中给出的建议开始

2) use the out of the box auditing features. 2)使用开箱即用的审核功能。 May or may not be what you are looking for but you can read more about that here and here 可能不是您要找的东西,但是您可以在这里这里阅读更多

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在CRM 2011中检索相关的实体ID - How retrieve related Entity ID in CRM 2011 在microsoft dynamics crm 2011中为LOOKUP字段添加值 - Adding value to LOOKUP field in microsoft dynamics crm 2011 从Silverlight应用程序更新查找字段-CRM 2011 - Updating a lookup field from a Silverlight app - CRM 2011 CRM 2011如何使用Java来使用子/相关实体表单中的值更新父实体字段 - CRM 2011 how to update a Parent entity field with values from a child/related entity form using Javascript CRM 2011-仅用名称设置查找值 - CRM 2011 - Set Lookup Value with just Name Dynamics CRM 2011-是否增加查找值? - Dynamics CRM 2011 - Adding Lookup Value? 如何使用crm sdk和C#从CRM 2011中的实体字段中获取选项集 - How to get the option set from a field in an entity in CRM 2011 using crm sdk and C# MS CRM c#:从字典中提取字符串guid,并在创建新的CRM记录时使用它填充查找字段 - MS CRM c#: Pickup string guid from dictionary and use it to populate lookup field when creating a new CRM record Dynamics CRM 2011,以编程方式设置货币字段 - Dynamics CRM 2011, setting currency field programmatically c#-动态CRM在线插件-使用字段值填充相关实体的属性 - c# - dynamics crm online plugin - use field value to populate attribute of related entity
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM