My code plugin:
using System; using System.ServiceModel; using Microsoft.Xrm.Sdk; namespace WASKOCRMBB { public class PostprojektCreate:IPlugin { public void Execute(System.IServiceProvider serviceProvider) { try { IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext)); IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { Microsoft.Xrm.Sdk.Entity opportunity = (Entity)context.InputParameters["Target"]; try { Microsoft.Xrm.Sdk.Entity m7_osoba = new Entity("m7_osoba"); Guid EntityId = opportunity.Id; m7_osoba["m7_szansasprzedazyid"] = new EntityReference("opportunity", EntityId); m7_osoba["m7_name"] = "Handlowiec zaangazawany"; m7_osoba["m7_udzialwmarzy"] = 100; service.Create(m7_osoba); } catch (Exception ex) { throw new Exception("Błąd przy dodawaniu handlowca zaangażowanego:" + ex.Message + "gdzie:" + ex.Source); } } } catch (Exception ex) { throw new Exception("Błąd ogolny:" + ex.Message + "ff:" + ex.Source); } // TODO: Implement your custom Plug-in business logic. } } }
In CRM gets the error:
Błąd ogolny:Błąd przy dodawaniu handlowca zaangażowanego:The specified object was not found.gdzie:Microsoft.Crm.Extensibility ff:WASKOCRM2011BB
Plugin is the creation of a record opportunity to create a record in another entity m7_osoba, combined with opportunityId reference.
verify that following fields and their data type are present and correct in your relevant entity and entity is published..
m7_szansasprzedazyid m7_name m7_udzialwmarzy
if they are present and data type is correct the try to debug your plug in as per following check list
MayankP My Blog Follow Me on Twitter
Better go for early binding process
Generate svcutil .cs file
http://msdn.microsoft.com/en-us/library/gg327844.aspx
so that there is no chance of missing attribute or entity naming
ms crm