Fetching irregular data from CRM Dynamics

2019-08-05 06:06发布

问题:

I've created a fetch XML that gives me all the contacts in a marketing list. I also would like to get the name of the list baked into the output. I've found two ways to achieve that, none of which is satisfactory to the pedantic me.

  1. Go to the DB and fetch the name as a separate request.
  2. Have an extra column containing the name of the marketing list for each contact.

I'll be getting multiple (maybe even all) marketing lists from CRM so the second version seems most suitable as I'll make one call and get it all into a data structure that I'll play with (DataSet and such are fun). The problem is there that we're getting a lot of redundancy. How can I resolve that?

回答1:

Are you able to add the marketing list name into the fetch?

For example:

Query:

<fetch mapping="logical" count="50" version="1.0">
    <entity name="list">
        <attribute name="listname" />
        <link-entity name="listmember" from="listid" to="listid">
            <link-entity name="contact" from="contactid" to="entityid">
                <attribute name="fullname" />
            </link-entity>
        </link-entity>
    </entity>
</fetch>

Result:

<resultset morerecords="0" paging-cookie="&lt;cookie page=&quot;1&quot;&gt;&lt;listid last=&quot;{4EDF9ECA-A108-E211-801E-00155D505002}&quot; first=&quot;{4EDF9ECA-A108-E211-801E-00155D505002}&quot; /&gt;&lt;/cookie&gt;">
    <result>
        <listname>Test Marketing List Name</listname>
        <listid>{4EDF9ECA-A108-E211-801E-00155D505002}</listid>
        <entityid.fullname>James Maths Wood</entityid.fullname>
    </result>
    <result>
        <listname>Test Marketing List Name</listname>
        <listid>{4EDF9ECA-A108-E211-801E-00155D505002}</listid>
        <entityid.fullname>James Wood</entityid.fullname>
    </result>
    <result>
        <listname>Test Marketing List Name</listname>
        <listid>{4EDF9ECA-A108-E211-801E-00155D505002}</listid>
        <entityid.fullname>WoodJ Test</entityid.fullname>
    </result>
</resultset>

As a side have you seen the FetchXml builder included in the Stunnware Tools available from http://www.stunnware.com, its for Crm 4 but handles pretty much every 2011 fetch I've needed to create. Note: it didnt create the fetch for the marketing list above correctly, I had to change the link-entity to contact to contactid manually.