Click here to Skip to main content
15,881,248 members
Articles / Programming Languages / Javascript
Article

How to get Advanced Find FetchXml Query in Dynamics CRM

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
11 Oct 2013CPOL 13.5K   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()<br />{<br />    if(document.getElementById('FetchXml'))<br />  {<br />    return document.getElementById('FetchXml').value;<br />  }<br />  else<br />  {<br />  return '';<br />  }<br />}<br />var sUrl = '/ISV/YourPage.aspx';<br />var sWin = window.open(sUrl,'','height=650,width=750,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,modal=yes');<br /><br />
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"><br />document.getElementById('crmAdvFindFetchXml').value=window.opener.getAdvFindFetchXml();<br /></script><br /><br />
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();<br />CrmService crmService=new CrmService();<br />/*<br />....<br />init your CrmService regarding your crm instance<br />....<br />*/<br /><br />crmService.Fetch(fetchXml);<br />XmlDocument xmlDoc = new XmlDocument();<br />xmlDoc.LoadXml(result);<br />XmlNodeList xmlNodes=xmlDoc.GetElementsByTagName("result");<br />                foreach (XmlNode item in xmlNodes)<br />                {<br />                    if (item["accountid"] != null) <br />/* accountid is just for example ,it can be any fieldid which is retrieved in fetchxml for your needs */<br />                    {<br />                        Response.Write(item["accountid"].InnerText);<br />                    }<br />                }<br />

Cheers,


 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
United States United States
The ASP.NET Wiki was started by Scott Hanselman in February of 2008. The idea is that folks spend a lot of time trolling the blogs, googlinglive-searching for answers to common "How To" questions. There's piles of fantastic community-created and MSFT-created content out there, but if it's not found by a search engine and the right combination of keywords, it's often lost.

The ASP.NET Wiki articles moved to CodeProject in October 2013 and will live on, loved, protected and updated by the community.
This is a Collaborative Group

755 members

Comments and Discussions

 
-- There are no messages in this forum --