Hye,
i have created a plugin on create of phonecall, i have set the TO value in regarding field if it is lead , contact , account or systemuser.
on create it works perfectly but on update it updates the record in regarding but not setting the name and showing null.
can any one have any idea about it ?
Code:
if (context.MessageName == "Update") {
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity PhoneCall = context.InputParameters["Target"] as Entity;
if (PhoneCall.Attributes.Contains("to"))
{
string LogicalName = ((EntityReference)((EntityCollection)PhoneCall["to"]).Entities[0].Attributes["partyid"]).LogicalName;
Guid EntityGuid = ((EntityReference)((EntityCollection)PhoneCall["to"]).Entities[0].Attributes["partyid"]).Id;
string _name = ((EntityReference)((EntityCollection)PhoneCall["to"]).Entities[0].Attributes["partyid"]).Name;
if (LogicalName == "contact" || LogicalName == "account" || LogicalName == "systemuser" || LogicalName == "lead")
{
EntityReference RegardingObject = new EntityReference();
RegardingObject.Id = EntityGuid;
RegardingObject.LogicalName = LogicalName;
RegardingObject.Name = _name;
if (PhoneCall.Attributes.Contains("regardingobjectid"))
{
PhoneCall["regardingobjectid"] = RegardingObject;
}
else {
PhoneCall.Attributes.Add("regardingobjectid", RegardingObject);
}
}
}
}