Hi
Please find below
Message name":Create
Primary Entity:Phone call
Operation: Pre
Here I have used mobilePhone field from contact moved to phoneCall entity
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity objEntity = (Entity)context.InputParameters["Target"];
if (objEntity == null || objEntity.LogicalName == null)
return;
EntityCollection objToEntityCollection = (EntityCollection)objEntity.Attributes["to"];
if (objToEntityCollection == null || objToEntityCollection.Entities.Count == 0)
return;
EntityReference objPartyEntityReference = (EntityReference)objToEntityCollection[0].Attributes["partyid"];
if (objPartyEntityReference == null || objPartyEntityReference.Id == null || objPartyEntityReference.LogicalName != "contact")
return;
QueryExpression objQueryContact = new QueryExpression("contact");
objQueryContact.ColumnSet = new ColumnSet(new string[1] { "mobilephone" });
ConditionExpression objConditionExpression = new ConditionExpression();
objConditionExpression.AttributeName = "contactid"; objConditionExpression.EntityName = "contact";
objConditionExpression.Values.Add(objPartyEntityReference.Id);
objQueryContact.Criteria.AddCondition(objConditionExpression);
EntityCollection arrContact = service.RetrieveMultiple(objQueryContact);
if (arrContact != null && arrContact.Entities.Count == 0)
return;
if (!objEntity.Attributes.Contains("phonenumber"))
{
if (arrContact.Entities[0].Attributes.Contains("mobilephone"))
{
// EntityReference objPhone = new EntityReference();
objEntity.Attributes["phonenumber"] = arrContact.Entities[0].Attributes["mobilephone"];
}
}
}