Hi Ramanathan,
Is this plugin looking authentic. please confirm.
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity account = (Entity)context.InputParameters["Target"];
if (account != null)
{
if (account.Attributes.Contains("parentaccountnumber") && account.Attributes["parentaccountnumber"] != null)
{
string ParentAccountNumber = null;
EntityReference entRef = (EntityReference)account.Attributes["parentaccountnumber"];
if (entRef.LogicalName == "account")
{
Guid accountid = entRef.Id;
string fetchQuery = string.Format(@"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='account'>
<attribute name='accountnumber' />
<attribute name='accountid' />
<filter type='and'>
<condition attribute='aac_parentaccountnumber' operator='not-null' />
</filter>
</entity>
</fetch>", accountid.ToString());
fetchQuery = string.Format(fetchQuery);
EntityCollection FetchParentAccountNumberResult = (EntityCollection)service.RetrieveMultiple(new FetchExpression(fetchQuery));
if (FetchParentAccountNumberResult != null && FetchParentAccountNumberResult.Entities.Count >0)
{
foreach (Entity ent in FetchParentAccountNumberResult.Entities)
{
if(ent.Attributes.Contains("parentaccountnumber") && ent.Attributes["parentaccountnumber"] != null)
{
ParentAccountNumber = ent.Attributes["parentaccountnumber"].ToString();
}
}
}
}
Entity acc = new Entity("account");
acc.Id = account.Id;
acc["parentaccountnumber"] = ParentAccountNumber;
service.Update(acc);
service.Create(acc);
}
}
}
}
catch (Exception e)
{
tracingService.Trace("FilteringAttributeForUpdate", e.ToString());
throw;
}