Use FetchXML to construct a query in Plugin, Console App, C#, and Workflow
4. This FetchXML query can be used in C# code, Plugin, Custom Workflow, and Console App.
Here in this blog, I'm going to show using organization service
Click here to convert fetchxml query to the query expression
Use the IOrganizationService.RetrieveMultiple method passing a FetchExpression where the Query property contains the FetchXml query.
The below code shows how to execute a FetchXML query using the Organizations Service:
// Retrieve all accounts owned by the user with read access rights to the accounts and
// where the last name of the user is not Kumar.
<entity name='account'>
<attribute name='accountid'/>
<attribute name='name'/>
<link-entity name='systemuser' to='owninguser'>
<filter type='and'>
<condition attribute='lastname' operator='ne' value='Kumar' />
</filter>
</link-entity>
</entity>
</fetch> ";
EntityCollection result = _service.RetrieveMultiple(new FetchExpression(fetchxml));
foreach (var c in result.Entities) { System.Console.WriteLine(c.Attributes["name"]); }
Refer to MS Docs for more details.
Happy CRMing...
Keep Learning!!!
No comments:
Post a Comment