Monday, January 7, 2008

FetchXML Query Examples

For those who don't know what Fetch in CRM 3.0 is I will briefly explain it.

Fetch is a method that CRM 3.0 uses to read data through it's API.
It is very easy to write a Fetch query.

Instead of writing a long tutorial I will try to explain how to use Fetch by examples.

The basic Fetch format:
<fetch mapping='logical'>
   <entity name='[Schema entity name]'>
      <all-attributes/>
      <filter type='and' or type='or'>
        <condition attribute='[Attribute name Case sensitive]' operator='eq' <--equals value='111038-18938-0...'/> 
     </filter>
   </entity>
</fetch>

Example 1: Fetch contacts for a particular owner
<fetch mapping='logical'>
   <entity name='contact'>
      <all-attributes/>
      <filter type='and' >
        <condition attribute='ownerid' operator='eq' value='111038-18938-0...'/> 
     </filter>
   </entity>
</fetch>
This query will retrieve the contact list for a particular owner.

Example 2: Activities for an owner that are due date
<fetch mapping='logical'>
   <entity name='activitypointer'>
      <all-attributes/>
      <filter type='and' >
        <condition attribute='ownerid' operator='eq' value='111038-18938-0...'/> 
       <condition attribute='scheduleend' operator='today'/>
     </filter>
   </entity>
</fetch>
This query gets the activities for a particular owner that are due today, the keyword today is understood by CRM 3.0 as the day of execution.

This will help you get your feet wet using Fetch.
It is easy to learn, especially with the use of an application called FetchXML Builder.

***If anyone knows the link to the website that hosts the FetchXML Builder, please send it to me.***

P.S: I accept private questions feel free to leave me a comment on the blog, I usually answer them quickly.

Have a great day.
Oshri Cohen

Labels: , , , , ,

6 Comments:

At January 28, 2008 at 11:21 AM , Anonymous Anonymous said...

I would like to fetch a XML query which will return all the products from a PriceList based on the pricelist thay have selected in the opportunity. I have created the XML and runned it fine outside CRM. But when use that queries within the CRM onload event for the opportunityproduct form it fails. How do I overcome this? Sorry I could paste the XMl code here!!!!

 
At January 28, 2008 at 1:18 PM , Blogger Oshri Cohen said...

it all depends on where you execute the code on the onload.
if you want to filter on a lookup than pass the XML to the lookup's fetchxml property.

Other wise give more detail as to what your are trying to accomplish.

Oshri cohen

 
At February 1, 2008 at 3:31 PM , Anonymous Anonymous said...

Hi,
Thanks for your examples and writeup on the Fetch. I am working on the Ms Crm, and I need to retrieve all the picklists and picklist items for a given Entity, say Accounts, Contact, etc. I am working on java. Please suggest how to do it.

Thanks and Regards

Yuva

 
At February 1, 2008 at 7:50 PM , Blogger Oshri Cohen said...

getting the picklist value is easy take a look at one of my posts on the blog, I discuss that exactly.

Oshri cohen

 
At February 6, 2008 at 2:06 PM , Anonymous Anonymous said...

Hi, Thanks for your reply. Now I am able to retrieve all the picklists and picklist items for a given Entity.

I have another doubt, I have a custom keyfield created at host MS crm. My webservices API is not updated and hence I dont have the getter/setter methods of the new custom field created.

Is it possible to create an entity, say Account, without using api's getter/setter methods. I am asking because my api doesnt have methods for updating newfield created to the Account object.

Thanks and Regards

Yuva

 
At February 11, 2008 at 11:21 PM , Anonymous Anonymous said...

Hello Oshri cohen

It is free Fetchxml builder on the link below.
http://www.jamesdowney.net/fetchxml.aspx

Best Wishes

Jaber

 

Post a Comment

Subscribe to Post Comments [Atom]

<< Home