I'm trying to write a plugin for the email entity in Microsoft Dynamics CRM Online. Let's say its called "Sample_PlugIn".
I want the plugin to retrieve the sender of the email, and write his/her email address into a field (new_samplefield) of the email.
The Plugin does some other stuff as well (and it's all working), but this part of the code is the one making problems. (My organisation service reference is called "service".)
try
{
Entity email = (Entity)context.InputParameters["Target"];
EntityCollection fromCollection = (EntityCollection)email.Attributes["from"];
if (fromCollection != null && fromCollection.Entities.Count > 0)
{
Entity sender = fromCollection[0];
email["new_samplefield"] = (string)sender.Attributes["internalemailaddress"];
}
service.Update(email);
}
Every time the plug-in is executed, I get this error:
Unexpected exception from plug-in (Execute): Sample_PlugIn.Sample_PlugIn: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
It'd be great if anyone could help me - thanks a lot!