DYNAMICS 365 HOW TO EXECUTE FETCHXML QUERIES IN C#
Previously, we saw
how to execute FetchXml query using Xrm.WebApi in JavaScript
In this quick post, we will see how to execute FetchXml query in C#.
- Prepare the FetchXml you want to execute whether from the Advanced Find, or any other FetchXml generator in the community
- Create the C# function you want to call in order to execute the retrieve request and Copy/Paste the FetchXml query
-
In order to be able to execute FetchXml queries in C#, you must use the FetchExpression class instead of QueryExpression as per the below
public void FetchXmlInFetchExpression()
{
var fetchQuery = @"
<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='account'>
<attribute name='name' />
<attribute name='primarycontactid' />
<attribute name='telephone1' />
<attribute name='accountid' />
<order attribute='name' descending='false' />
<filter type='and'>
<condition attribute='primarycontactid' operator='not-null' />
<condition attribute='name' operator='like' value='%Northwind%' />
</filter>
</entity>
</fetch>";
var objRecords = AdminService.RetrieveMultiple(new FetchExpression(fetchQuery));
}
- The above fetchXml is a very simple query, but you can build and execute more complex queries based on your needs
Hope This Helps!
Comments
Post a Comment