Monday, January 14, 2008

Create Relationships in CRM 3.0 programmatically

Ever have the need to programmatically create a relationship between contacts or between a contact and an account?

I stumbled on this problem when a client requested that I import relationships from the legacy ACT! 6 database.
The field where [Lead source] and [referred by].

The relationship entity schema name is "customerrelationship".
The entity has the following important attributes:

Attribute Description
customerroledescription/partnerroledescription The description for the relationship
customerid/partnerid The Lookup for the customer and partner respectively
customerroleid/partnerroleid The lookup for the relationship role (This can be configured in the Settings section of CRM)


It is that simple, create your class than call the service.create method of the CRM 3.0 to create the relationship.

Have a great day.

Oshri Cohen

Labels: , , ,

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: , , , , ,