Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

ExecuteByIdUserQueryRequest xml (string) results to EntityCollection

(0) ShareShare
ReportReport
Posted on by 2,379

Hi all,

I want to minimize my QueryExpression codes by using "SystemViews" or "User Views (saved advanced find queries)", so need to use "ExecuteByIdUserQueryRequest" (https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.executebyiduserqueryrequest.aspx) .

However this returns dataset with Xml (string) and I can not use it, in SDK notes,

This message returns a String type that specifies the XML data containing the results of the query. This XML string is in the following format:

<resultset> + <result>result1</result><result>result2</result> + ... + </resultset>


How can I convert this Xml dataset to EntityCollection or List<Entity>

Thank you

*This post is locked for comments

  • Verified answer
    Emre GULCAN Profile Picture
    Emre GULCAN 2,379 on at
    RE: ExecuteByIdUserQueryRequest xml (string) results to EntityCollection

    Hi guys,

    Thank you for all replies.

    I realized that resultset (xml) doesn't contain metadata for attributes, I think we can't convert directly to Entity or EntityCollection because of this. ExecuteByIdUserQueryRequest's response (ExecuteByIdUserQueryResponse) "Result (msdn.microsoft.com/.../microsoft.xrm.sdk.organizationresponse.results.aspx)" property is "ParameterCollection" that holds Key(string) and Value(object) 

    Maybe I can code a custom converter for this but I think it's a bit hard without metadata (just need string parsing to guess attribute type) and it's not "wooow-thing" for this time.

    As you can see below (redlines) "ParentCustomerId" is a lookup, "gendercode" is an optionset and "aliased.telephone1" is a string and it's joined entity's (company) telephone field, but there is no metadata about attributes datatypes etc.

    <result>
      <fullname>TEST 01</fullname>
      <contactid>{2C41CF5B-D1FA-E611-8117-005056B0178D}</contactid>
      <parentcustomerid yomi="" type="1" name="L2A Company" dsc="">{79290D50-EAE0-E611-8116-005056B0178D}</parentcustomerid>
      <gendercode name="Erkek" formattedvalue="1">1</gendercode>
      <a_dc9b80f8c78146d89fd6a3b610836975.telephone1>33344455</a_dc9b80f8c78146d89fd6a3b610836975.telephone1>
    </result>
    <result>
      <fullname>TEST 02</fullname>
      <contactid>{FE554A7F-EBD4-E611-8114-005056B0178D}</contactid>
      <emailaddress1>emregulcan@gmail.com</emailaddress1>
    </result>


    Thanks again, I'm checking "suggested" your answers and maybe I should close this subject at this point :), but if you have any idea will welcome

  • RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: ExecuteByIdUserQueryRequest xml (string) results to EntityCollection

    Hi Emre,

    I handle these kind of scenarios (i.e. where there is a need to frequently update the query), I keep the fetchxml in the config entity and then execute that query. This way I never have to update my code.

    I know this is again will be 2 server calls if you look it that but in my case, I usual have somoe or the other config calue so I have to make a call to my config entity.

  • TigerJ Profile Picture
    TigerJ 115 on at
    RE: ExecuteByIdUserQueryRequest xml (string) results to EntityCollection

    I see that makes sense.

  • Emre GULCAN Profile Picture
    Emre GULCAN 2,379 on at
    RE: ExecuteByIdUserQueryRequest xml (string) results to EntityCollection

    Hi guys,

    Thank you for your responses.

    @Ravi,

    You're right I can use your way however there will be 2 queries, first retrieve for savedquery 's fetchxml and then main query retrieve with savedquery 's fetchxml.

    @Jimmy,

    I tried to deserialize returned xml however was not succeed because of resultset xml's structure (I think). I'm trying to different ways.

    <resultset morerecords="0" paging-cookie="&lt;cookie page=&quot;1&quot;&gt;&lt;fullname last=&quot;User3 Customer&quot; first=&quot;E G&quot; /&gt;&lt;contactid last=&quot;{1C96C50C-70F8-E611-8117-005056B0178D}&quot; first=&quot;{2C41CF5B-D1FA-E611-8117-005056B0178D}&quot; /&gt;&lt;/cookie&gt;">

      <result>
        <fullname>E G</fullname>
        <contactid>{2C41CF5B-D1FA-E611-8117-005056B0178D}</contactid>
      </result>
      <result>
        <fullname>TEST 01</fullname>
        <contactid>{FE554A7F-EBD4-E611-8114-005056B0178D}</contactid>
        <emailaddress1>test01@gmail.com</emailaddress1>
      </result>
      <result>
        <fullname>TEST 01</fullname>
        <contactid>{202199FE-EDE0-E611-8116-005056B0178D}</contactid>
      </result>
    </resultset>


    Basically I want manage my backend with Dynamics CRM 's advanced find queries, for example thinking about contact.

    When I need a new column or filter, just prepare (and save) an advanced find query (userquery) and use it inside my code instead of change my QueryExpression codes, so if I need a new filter just add to savedquery and save it, just that. But this string(xml) result breaks my way :)

    Actually I think it's a bit utopian :) but if I'll solve this it'll be perfect.

  • Verified answer
    TigerJ Profile Picture
    TigerJ 115 on at
    RE: ExecuteByIdUserQueryRequest xml (string) results to EntityCollection

    You will have to deserialize the xml

    Here is an example where a contact is first serialized into xml from an entity and then deserialized back.

    msdn.microsoft.com/.../hh675409.aspx

    I think your efforts would be better to standardize your query expressions in a way you can make a function return an entity collection instead of the path you are headed down.

  • Verified answer
    RaviKashyap Profile Picture
    RaviKashyap 55,410 on at
    RE: ExecuteByIdUserQueryRequest xml (string) results to EntityCollection

    Hi Emre,

    It doesn't look like there is anything available to convert the XML response to Entity Collections. And now I am wondering what would be the actual scenario where we would be using the result returned as XML string?

    If you want to minimize the query expression code and execute the query from the saved view, you could still do a retrieve of the saved query entity and then do a retrieve multiple to get the records for that view by passing the returned fetchxml.

    Something like this-

    ==========

    var targetEntity = service.Retrieve("savedquery", new Guid("00000000-0000-0000-00AA-000010001002"), new ColumnSet("fetchxml"));

    var result = service.RetrieveMultiple(new FetchExpression(targetEntity["fetchxml"].ToString()));

    ==========

    Hope this helps.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Tip: Become a User Group leader!

Join the ranks of valued community UG leaders

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,516 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,329 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans