Actually i tried in plug-in that concept. but it did not work.
this is the code which i used.Is there any mistake in this???
My need is when i create an appointment the values in location field should be copied to firstname of contact entity.
public void Execute(IPluginExecutionContext context)
{
DynamicEntity entity = null;
if (context.InputParameters.Properties.Contains("Target") &&
context.InputParameters.Properties["Target"] is DynamicEntity)
{
entity = (DynamicEntity)context.InputParameters.Properties["Target"];
if (entity.Name != EntityName.appointment.ToString())
return;
}
else
{
return;
}
try
{
Guid appointmentID = new Guid(context.OutputParameters["id"].ToString());
ICrmService crmservice = context.CreateCrmService(true);
appointment appObj = (appointment)crmservice.Retrieve(EntityName.appointment.ToString(), appointmentID, new ColumnSet(new string[] { "regardingobjectid", "location" }));
if (appObj.regardingobjectid == null || appObj.regardingobjectid.type != "contact")
{
return;
}
Guid contactID = appObj.regardingobjectid.Value;
contact cnt = new contact();
cnt.contactid = new Key();
cnt.contactid.Value = contactID;
cnt.firstname = appObj.location;
crmservice.Update(cnt);
}
catch (System.Web.Services.Protocols.SoapException ex)
{
throw new InvalidPluginExecutionException(
"Invalid plug-in.", ex);
}
}