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,