Hi,
I think i may be getting myself confused with this, but how do you retrieve the To & From fields along with the rest of an Email record? So for example, I have some fetch xml (although a Query Expression solution would also be fine):
string fetchXml = @"
<fetch mapping='logical'>
<entity name='email'>
<attribute name='subject'/>
<attribute name='regardingobjectid'/>
<attribute name='from'/>
<attribute name='to'/>
<attribute name='prioritycode'/>
<attribute name='statuscode'/>
<attribute name='modifiedon'/>
<attribute name='activityid'/>
<order descending='false' attribute='subject'/>
<link-entity name='contact' alias='ag' to='regardingobjectid' from='contactid'>
<filter type='and'>
<condition attribute='examplecondition' value='1' operator='eq'/>
<condition attribute='anotherexamplecondition' value='5' operator='eq'/>
</filter>
</link-entity>
</entity>
</fetch>";
XDocument document = crmService.ToXDocument(contactEmailfetchXml);
var results = document.Root.Elements("result").Select(e =>
new Email
{
ActivityId = e.Element("activityid").ToGuid(),
Subject = e.Element("subject").Val(),
//From = e.Element("from").Val(),
//To = e.Element("to").Val(),
//CC = e.Element("cc").Val(),
PriorityCode = e.Element("prioritycode").Val()
}).ToList();
And the 'Val' extension method is just:
public static string Val(this XElement element)
{
return element != null
? element.Value
: String.Empty;
}
Any help would be really appreciated.
Thanks.