Fetch It Part 2

In the first blog on using Fetch XML, I introduced a tool that I had created that would allow you to execute Fetch XML statements to retrieve CRM data. In this blog, I want to discuss some of the inner workings to executing Fetch XML statements to retrieve more than a single page of records. Here’s the link to the updated FetchIt tool

The mechanism is a paging cookie that tells the CRM system were to start the retrieve from. The paging cookie is returned on a fetch execute statement in the data set. The first step is to execute a fetch xml request. This is pretty simple and documented well in the SDK.

string QueryString = @”<fetch mapping=’logical’><entity name=’new_test’><all-attributes/></entity></fetch>”;
Result = this.m_crmService.Fetch(QueryString);

 

 

This will return a string of xml data.

<resultset morerecords=”1″ paging-cookie=”&lt;cookie page=&quot;1&quot;&gt;&lt;new_testid last=&quot;{C855BD56-D955-DE11-90B3-001E0B5E0BF6}&quot; first=&quot;{37F4AB96-D755-DE11-90B3-001E0B5E0BF6}&quot; /&gt;&lt;/cookie&gt;”><result>……

Notice in the root element are the attributes morerecords and paging-cookie.

The morerecords indicates there is more data from the query. The limit per retrieve is 5000 records. To get more, you simply need to add the paging cookie to the next request.

string QueryString = @”<fetch mapping=’logical’ page=’2′ count=’5000′ ” + Cookie + “><entity name=’new_test’><all-attributes/></entity></fetch>”;

 

 

To accomplish this you’ll need to do a bit of parsing and string manipulation. Make sure you grab the quote on the end.

 

 

string Cookie= paging-cookie=”&lt;cookie page=&quot;1&quot;&gt;&lt;new_testid last=&quot;{C855BD56-D955-DE11-90B3-001E0B5E0BF6}&quot; first=&quot;{37F4AB96-D755-DE11-90B3-001E0B5E0BF6}&quot; /&gt;&lt;/cookie&gt;”

 

 

then insert into the query along with a paging attribute.

string QueryString2 = @”<fetch mapping=’logical’ page=’2′ count=’5000′” + Cookie + “’><entity name=’new_test’><all-attributes/></entity></fetch>”;

 

 

Next, all you need to is execute the fetch request with the new string. On each call, increase the page number from the last until morerecords = 0.

Here’s some code snippets. Make sure you add appropriate error handling. I put this together as a conceptual example.

 

 

string GetCookie(int idx,string DataChunk)

 

 

{

 

 

    int end = DataChunk.IndexOf(“>”, idx);

 

 

    int start = DataChunk.IndexOf(“paging-cookie=”);

 

 

    int nCnt = end – start;

 

 

    string Cookie = DataChunk.Substring(start, nCnt);

 

 

    return Cookie;

 

 

}

 

 

 

 

 

public static string InsertCookie(string fetchXml,

                     int PageNum, string Cookie)

 

 

{

 

 

    string Root = “<fetch mapping=’logical’ page='”

     + PageNum.ToString() + “‘ count=’5000’ ”

     + Cookie + “>”;

 

 

 

 

 

    int end = fetchXml.IndexOf(“>”);

 

 

    if (end < 0)

 

 

    {

 

 

      return “”;  // need to handle empty string

    }

 

 

 

 

 

    StringBuilder builder

            = new StringBuilder(fetchXml);

 

 

    int RootEnd = fetchXml.IndexOf(“>”);

 

 

    if (RootEnd > -1)

 

 

    {

 

 

        int length = RootEnd + 1;

 

 

 

 

 

        // Remove old root attributes.

 

 

        builder.Remove(0, length);

 

 

       

 

 

        // Insert new root element attributes

        builder.Insert(0, Root);

 

 

    }

 

 

  

 

 

    return builder.ToString();

 

 

}

 

 

 

 

 

 

cheers

-jonw

 

Posted: Wednesday, June 17, 2009 5:30 PM by JonWhite | 1 Comments

Enhanced Internet Lead Capture capabilities now available

For those currently using the Internet Lead Capture capabilities within CRM Online you may have noticed that the functionality was enhanced recently. 

Here are some highlights of what has improved:

– Canadian customers can now take advantage of Internet Lead Capture (AdCenter integration does not apply in Canada)

– There is support for vanity URLs which allows you to leverage your unique CRM Online org name for a specific landing page URL if you decide to have Microsoft host your internet lead capture page

– You have the ability to add any lead field (including custom lead fields) to the Internet Lead Capture web form

– There is an improved Lead Capture Home Page with embedded charts to show lead capture effectiveness

If you aren’t using this functionality today, you can easily activate it by clicking on “Landing Pages” or “Internet Leads” from the Sales or Marketing Tab within the left navigation

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: