Plugins CRM 2011:创建重复记录的插件

Plugins CRM 2011:创建重复记录的插件,plugins,dynamics-crm-2011,Plugins,Dynamics Crm 2011,我创建了一个简单的插件来创建引用父记录的重复记录 这是我的密码 var pluginExecutionContext = localContext.PluginExecutionContext; IOrganizationService service = localContext.OrganizationService; abc= pluginExecutionContext.InputParameters["Target"] as Enti

我创建了一个简单的插件来创建引用父记录的重复记录

这是我的密码

        var pluginExecutionContext = localContext.PluginExecutionContext;

        IOrganizationService service = localContext.OrganizationService;

        abc= pluginExecutionContext.InputParameters["Target"] as Entity;

        if (pluginExecutionContext.Depth == 1)
        {
            Guid abcId = abc.Id;
            Entity abcCopy = new Entity("mcg_abc");


            if (abc.Attributes.Contains("mcg_abccategoryoptioncode"))
            {
                abcCopy.Attributes["mcg_abccategoryoptioncode"] = abc.GetAttributeValue<OptionSetValue>("mcg_abccategoryoptioncode");
            }

            if (abc.Attributes.Contains("mcg_effectivedate"))
            {
                abcCopy.Attributes["mcg_effectivedate"] = isp.GetAttributeValue<DateTime>("mcg_effectivedate");
            }

            if (abc.Attributes.Contains("mcg_startdate"))
            {
                abcCopy.Attributes["mcg_startdate"] = isp.GetAttributeValue<DateTime>("mcg_startdate");
            }

            if (abc.Attributes.Contains("mcg_enddate"))
            {
                abcCopy.Attributes["mcg_enddate"] = isp.GetAttributeValue<DateTime>("mcg_enddate");
            }

            if (abc.Attributes.Contains("mcg_amendeddate"))
            {
                abcCopy.Attributes["mcg_amendeddate"] = isp.GetAttributeValue<DateTime>("mcg_amendeddate");
            }
             if ((abc.GetAttributeValue<OptionSetValue>("mcg_abccategoryoptioncode").Value) == 803870001)
                {
              //Some more fields;     

                }
               else
               {
              //Some more fields;    
               }
            // SOme more fields;
            abcCopy.Attributes["mcg_parentabc"] = new EntityReference("mcg_abc", abc.Id);
             service.Create(abcCopy);
var-pluginExecutionContext=localContext.pluginExecutionContext;
IOOrganizationService=localContext.OrganizationService;
abc=pluginExecutionContext.InputParameters[“Target”]作为实体;
if(pluginExecutionContext.Depth==1)
{
Guid abcId=abc.Id;
实体abcCopy=新实体(“mcg_abc”);
if(abc.Attributes.Contains(“mcg_abccategoryoptioncode”))
{
abcCopy.Attributes[“mcg_abccategoryoptioncode”]=abc.GetAttributeValue(“mcg_abccategoryoptioncode”);
}
if(abc.Attributes.Contains(“mcg_生效日期”))
{
abcCopy.Attributes[“mcg_effectivedate”]=isp.GetAttributeValue(“mcg_effectivedate”);
}
if(abc.Attributes.Contains(“mcg_startdate”))
{
abcCopy.Attributes[“mcg_startdate”]=isp.GetAttributeValue(“mcg_startdate”);
}
if(abc.Attributes.Contains(“mcg_enddate”))
{
abcCopy.Attributes[“mcg_enddate”]=isp.GetAttributeValue(“mcg_enddate”);
}
if(abc.Attributes.Contains(“mcg_修正日期”))
{
abcCopy.Attributes[“mcg_amendeddate”]=isp.GetAttributeValue(“mcg_amendeddate”);
}
if((abc.GetAttributeValue(“mcg_abccategoryoptioncode”).Value)==80387001)
{
//更多的领域;
}
其他的
{
//更多的领域;
}
//更多的领域;
abcCopy.Attributes[“mcg_parentabc”]=新的实体引用(“mcg_abc”,abc.Id);
创建服务(abcCopy);
}

现在的问题是,下面的检查之前的所有字段都被复制了

 if ((abc.GetAttributeValue<OptionSetValue>("mcg_abccategoryoptioncode").Value) == 803870001)
if((abc.GetAttributeValue(“mcg_abccategoryoptioncode”).Value)==80387001)
但是,不会复制此检查后的字段


如果有人能告诉我我犯了什么错误,请告诉我。

如果您从Target获取字段,则此字段已在客户端更新。如果字段未更新-它将不在目标中。您应该使用图像获取未更改字段的值。

该字段必须为空,因此可能会出现异常。尝试使用插件图像或将代码更改为以下方式:

if (abc.Attributes.Contains("mcg_abccategoryoptioncode")){
  if ((abc.GetAttributeValue<OptionSetValue>("mcg_abccategoryoptioncode").Value) == 803870001)
....
if(abc.Attributes.Contains(“mcg_abccategoryoptioncode”)){
if((abc.GetAttributeValue(“mcg_abccategoryoptioncode”).Value)==80387001)
....

您是说执行的是
if
部分,而不是
else
(或vis-a-versa),还是说
//更多字段;
实际上没有设置任何内容?