Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

C# Plugin Check whether entity contains field fails - given key not in the dictionary

$
0
0

I have a plugin that runs on an emails, it checks the sending contact for a parent account to then use that account on the case.

In the scenario where the contact doesn't have a parent contact, I'm getting an error even though I believe my short-circuited logic shouldn't evaluate the second expression

Entity eContact = service.Retrieve("contact", _sender.Id, new ColumnSet("parentcustomerid"));
tracer.Trace(eContact.Contains("parentcustomerid").ToString()); //returns false

foreach (KeyValuePair<string, object> att in eContact.Attributes) //only gives contact id
    if (att.Value.GetType() == typeof(EntityReference))
        tracer.Trace(att.Key + ": " + ((EntityReference)att.Value).Name);
    else
        tracer.Trace(att.Key + ": " + att.Value.ToString());

if (eContact.Contains("parentcustomerid") && eContact["parentcustomerid"] != null && ((EntityReference)eContact["parentcustomerid"]).LogicalName == "account")//Given Key not in Distionary error
{
    tracer.Trace("Set Account");
    eCase["dsg_account"] = (EntityReference)eContact["parentcustomerid"];
}



Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images