I'm trying to update entity A from entity B on click of save button. Below is my code
using System;
using Microsoft.Xrm.Sdk;
namespace MyPlugin
{
public class Class1 : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = (IOrganizationService)factory.CreateOrganizationService(context.UserId);
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
if (context.InputParameters != null)
{
try
{
Entity entity = context.PostEntityImages["PostImage"];
System.Diagnostics.Debug.WriteLine(entity.Attributes);
string m = (string)entity.Attributes["new"];
tracingService.Trace(m);
string sig = (string)entity.Attributes["sig"];
tracingService.Trace(sig);
System.Diagnostics.Debug.WriteLine(m + sig);
EntityReference parent = (EntityReference)entity.Attributes["contact"];
string required = m + sig;
Entity parententity = new Entity("contact");
parententity.Id = parent.Id;
parententity.Attributes["new_current"] = required;
service.Update(parententity);
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException(ex.Message);
}
}
}
}
}
I'm getting an error in line Entity entity = context.PostEntityImages["PostImage"]; says "Key doesn't exist in the dictionary". Am I doing anything wrong in getting post image of the entity?
Any help would be appreciated.
Thanks