Thursday, July 14, 2011

FetchXML Happiness in CRM 4.0

One of the best things that happened at Convergence 2011 (besides winning the Xbox Kinect, of course), was learning that you can get the FetchXML from an Advanced Find very easily via the CRM 2011 interface.

However, I still have to work with CRM 4.0, where the FetchXML is completely inaccessible...or is it?

I came across a wonderful post about retrieving the FetchXML from an Advanced Find in CRM 4.0:http://ronaldlemmen.blogspot.com/2006/11/using-advanced-find-for-fetchxml.html

It's an old post, from 2006, but still as useful today as it was then.

The long and short of it is that after you hit the Find button on the Advanced Find dialog, just hit F11 to full-screen the dialog, which gives you an address bar, and then paste the following Javascript into that address bar:

javascript:prompt("my query:", resultRender.FetchXml.value);

It will bring up a dialog with the FetchXML in it, that you can grab and do with what you will. e.g.:


<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
  <entity name="contact">
    <attribute name="fullname"/>
    <attribute name="telephone1"/>
    <attribute name="new_jobtitle"/>
    <attribute name="parentcustomerid"/>
    <attribute name="ownerid"/>
    <attribute name="jobtitle"/>
    <attribute name="emailaddress1"/>
    <attribute name="contactid"/>
    <order attribute="fullname" descending="false"/>
    <filter type="and">
      <condition attribute="firstname" operator="eq" value="Bob"/>
    </filter>
  </entity>
</fetch>

In my case (I was writing functional tests for a plugin), I needed to limit the number of results returned by the query, which you normally can't do via the CRM 4.0 interface. I also didn't need all the fields that would normally be returned.

However, it's very easy to add edit to the XML to bring back what you need and limit the number of records returned. I removed everything but the contactid, and added an attribute to the root element to only bring back the first record. The final FetchXML I used looked something like this (though I wasn't looking for guys named "Bob", my query was a little more complex):


<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false" count="1">
  <entity name="contact">
    <attribute name="contactid"/>
    <filter type="and">
      <condition attribute="firstname" operator="eq" value="Bob"/>
    </filter>
  </entity>
</fetch>

This gave me exactly what I needed , the first contactid to match my criteria, thanks to some simple tricks to get access to the FetchXML.

Tuesday, April 26, 2011

Dynamics CRM Environment Confusion

Currently I'm working with Microsoft Dynamics CRM, extending the platform, writing custom code & web services and the like. And here's a small problem that I've run in to...

If your company is anything like my company, you don't just have one CRM environment. In fact, we don't just have two CRM environments, we have five environments, each progressing one step up from Development, through QA, and into Production. Even though the Internet Explorer address bar clearly shows which environment I'm in when it's maximized, I frequently get confused, or worse, I can't see which environment is which in the status bar preview.

However, I have discovered how to solve this problem. It's not supported, technically, but we're talking about testing & development environments, not a production one. Also, the change is so minor, it's easy enough to undo it and make sure it isn't the cause of a problem, before calling the Microsoft support line.

If you look in the CRMWeb\_imgs folder in the installation directory (ours is C:\Microsoft CRM\CRMWeb\_imgs), there is a file called "masthead.jpg", that looks like this:





If you update this image, replacing it with one of the exact same dimens
ions, like this one:




it will be seamlessly integrated into CRM. See for yourself:



















Voila! Instantly recognizable environment indicators. And if you're just a little OCD like me, I also set the background color on those servers' desktops to the exact same color as the masthead, just so that when I remote into them, it's clear where's I am.