Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 8223

CRM 2011 : Plugin to create duplicate records

$
0
0
Hi, i created a simple plugin to create a duplicate record that refers to the parent record.

Here is my code

            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);
}


Now the problem is all the fields before the below check are getting copied

     if ((abc.GetAttributeValue<OptionSetValue>("mcg_abccategoryoptioncode").Value) == 803870001)

However fields after this check are not getting copied.

Please if anybody could suggest what mistake i have made.

Viewing all articles
Browse latest Browse all 8223

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>