Hi,
I have created a plugin such that whenever an account created, a default contact will be created. It created successfully, but below red marked fields are not saved. Can you please tell me why ?
public void Execute(IServiceProvider serviceProvider)
{
try
{
IPluginExecutionContext _context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory _servieFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService _organizationService = _servieFactory.CreateOrganizationService(_context.UserId);
if (_context.InputParameters.Contains("Target") && _context.InputParameters["Target"] is Entity)
{
Entity entityAccount = (Entity)_context.InputParameters["Target"];
Entity entityContact = new Entity("contact");
entityContact["firstname"] = "abc";
entityContact["lastname"] = "xyz";
entityContact["jobtitle"] = "Consultant";
entityContact["emailaddress1"] = "abc@gmail.com";
entityContact["address1_line1"] = "new address1";
entityContact["address1_line2"] = "new address2";
entityContact["address1_line3"] = "new address3";
entityContact["address1_city"] = "new city";
entityContact["address1_postalcode"] = "123456";
entityContact["parentcustomerid"] = new EntityReference("account", entityAccount.Id); ;
_organizationService.Create(entityContact);
}
}
catch (Exception ex)
{
throw ex;
}
}
*This post is locked for comments
I have the same question (0)