Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How to get Advanced Find FetchXml Query in Dynamics CRM

0.00/5 (No votes)
6 Feb 2010 1  
For one of my applications , I needed to get the all the records,found in AdvancedFind and manage these records. If the record count is less than max

This articles was originally at wiki.asp.net but has now been given a new home on CodeProject. Editing rights for this article has been set at Bronze or above, so please go in and edit and update this article to keep it fresh and relevant.

For one of my applications , I needed to get the all the records,found in AdvancedFind and manage these records. If the record count is less than max display number of grid view ,there is no problem. What if the the records are more than this number ? My solutios is to get the Advanced Find FetchXml Query and evaluate it on my custom aspx page through a grid button by using JavaScript. Here is the JavaScript code which need be placed as JavaScript attribute in custom grid button.In Crm Sdk,you can find how to add a custom button on a grid.
function getAdvFindFetchXml()
{
if(document.getElementById('FetchXml'))
{
return document.getElementById('FetchXml').value;
}
else
{
return '';
}
}
var sUrl = '/ISV/YourPage.aspx';
var sWin = window.open(sUrl,'','height=650,width=750,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,modal=yes');

And now , you need to create a custom aspx page to handle the events and FetchXml Query. 1-Create an aspx page. 2-Add an asp:textbox or asp:hiddenfield named "crmAdvFindFetchXml" to your page. 3-Copy and paste the javascript code below before the </html> tag of your page.This code will assign the Advanced Find FetchXml Query to your control.
<script type="text/javascript" language="javascript">
document.getElementById('crmAdvFindFetchXml').value=window.opener.getAdvFindFetchXml();
</script>

4-Add an asp:button to your page and create a post back button click event for the button. 5- Copy and paste the code below in the asp:button click event.
string fetchXml=crmAdvFindFetchXml.Text.Trim();
CrmService crmService=new CrmService();
/*
....
init your CrmService regarding your crm instance
....
*/

crmService.Fetch(fetchXml);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(result);
XmlNodeList xmlNodes=xmlDoc.GetElementsByTagName("result");
foreach (XmlNode item in xmlNodes)
{
if (item["accountid"] != null)
/* accountid is just for example ,it can be any fieldid which is retrieved in fetchxml for your needs */
{
Response.Write(item["accountid"].InnerText);
}
}

Cheers,


 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here