In previous version i.e. 3.0 on updating certain field in pre/post update used to lead to circular reference.
The only way to update in case of crm 3.0 was to modify the entityxml recieived as ref parameter for preUpdate event handler.
In CRM 4.0 to do the same we can add/update the properties passed as inputparameters to the context for pre-update.
public void Execute(IPluginExecutionContext context)
{
DynamicEntity entity = (DynamicEntity)context.InputParameters.Properties[“Target”];
if (entity.Name == EntityName.lead.ToString())
{
// firstname and lastname are already properties of the entity which are not null and
// therefore are passed as inputparamters
String firstName = “Nishant”;
entity.Properties[“firstname”] = firstName;
String lastName = “Rana”;
entity.Properties[“lastname”] = lastName;
//or setting a value of a field whose value is null i.e. not passed as inputparameter
StringProperty subject = new StringProperty(“subject”, “Test Subject”);
entity.Properties.Add(subject);
}
}
The above plugin is registered for lead’s pre-update event.
Using service.update would lead to “server is unable to process the request error” as it automatically checks for the circular reference, if the crmService has been created using context.CreateCrmService() method.
For CRM 3.0 refer this wonderful article
http://www.stunnware.com/crm2/topic.aspx?id=Callout2
Bye…
Discover more from Nishant Rana's Weblog
Subscribe to get the latest posts sent to your email.
