Friday, February 26, 2010

Using Advanced Find to generate FetchXml

This post doesn't contain anything original. I stole this from here (good ones borrow, great ones steal). Here's how you use the Advanced Find functionality in CRM to create proper fecthXml.

  • Open advanced Find and press Ctrl-n. This will open Advanced Find in a separate window that gives you access to the browser bar
  • Define your query
  • Execute the query
  • Paste the following into the address/url bar in the browser:
    javascript:alert(resultRender.FetchXml.value); -- This will cause a javascript alert to pop up and display your fetchxml
Props to Ronald Lemmen for this excellent tip.

I just found another bit of of JavaScript that can assist you with this:

 javascript:void( new function(){ prompt("Fetch Parameters:",getFetchParams());function getFetchParams(){ return "FetchXml:\n" + advFind.FetchXml + "\n\n" + "LayoutXml:\n" + advFind.LayoutXml + "\n\n" + "EntityName:\n" + advFind.EntityName + "\n\n" + "DefaultAdvancedFindViewId:\n" + advFind.DefaultAdvancedFindViewId } } ) 


Thanks to Adi Katz for this great tip!


Happy coding!

3 comments:

  1. Hi
    This does not work with CRM 2011, can you post the code for 2011?
    Mike

    ReplyDelete
  2. Sorry for the delay on this.

    javascript:alert(document.frames[0].document.getElementsByTagName("table").advFind.FetchXml)

    ReplyDelete
  3. javascript:void( new function(){ prompt("Fetch Parameters:",getFetchParams());function getFetchParams(){ return "FetchXml:\n" + document.frames[0].document.getElementsByTagName("table").advFind.FetchXml } } )

    ReplyDelete