locked
Fetching PartyList Members via SOAP RRS feed

  • Question

  • Hi Folks

    What is the recommended way to fetch members of a PartyList attribute?  Say I want to retrieve the 'to' contacts for a specific phonecall, how would I go about doing this?  I've searched and searched and I can't find anything of use at all.

    Cheers!

    Wednesday, August 13, 2014 12:59 PM

Answers

  • You should check out the SoapLogger project in the SDK to convert a request from .NET into the SOAP equivalent.

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
      <s:Body>
        <Retrieve xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
          <entityName>phonecall</entityName>
          <id>d945d614-ec22-e411-8f50-6c3be5a60c50</id>
          <columnSet xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
            <a:AllColumns>false</a:AllColumns>
            <a:Columns xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
              <b:string>to</b:string>
            </a:Columns>
          </columnSet>
        </Retrieve>
      </s:Body>
    </s:Envelope>

    In the response you'd see:

    <a:KeyValuePairOfstringanyType>
      <b:key>partyid</b:key>
      <b:value i:type="a:EntityReference">
    	<a:Id>e316c71e-2218-e411-8f50-6c3be5a60c50</a:Id>
    	<a:LogicalName>account</a:LogicalName>
    	<a:Name>XYZ</a:Name>
      </b:value>
    </a:KeyValuePairOfstringanyType>


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Wednesday, August 13, 2014 4:08 PM
    Moderator

All replies

  • You can do it fairly easily using the REST endpoint:

    var req = new XMLHttpRequest();
    req.open('GET', encodeURI(Xrm.Page.context.getClientUrl() + "/XRMServices/2011/OrganizationData.svc/PhoneCallSet(guid'D945D614-EC22-E411-8F50-6C3BE5A60C50')?$select=phonecall_activity_parties/PartyId&$expand=phonecall_activity_parties"), true);
    req.setRequestHeader('Accept', 'application/json');
    req.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
    req.onreadystatechange = function () {
        if (this.readyState === 4) {
            req.onreadystatechange = null;
            if (this.status === 200) {
                var result = JSON.parse(req.responseText).d;
                var phonecall_activity_parties_PartyId = result.phonecall_activity_parties.PartyId;
            }
            else {
                alert(this.statusText);
            }
        }
    };
    req.send();

    The result would look like:

    {  
       "d":{  
          "__metadata":{  
             "uri":"https://test.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/PhoneCallSet(guid'd945d614-ec22-e411-8f50-6c3be5a60c50')",
             "type":"Microsoft.Crm.Sdk.Data.Services.PhoneCall"
          },
          "phonecall_activity_parties":{  
             "results":[  
                {  
                   "__metadata":{  
                      "uri":"https://test.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/ActivityPartySet(guid'da45d614-ec22-e411-8f50-6c3be5a60c50')",
                      "type":"Microsoft.Crm.Sdk.Data.Services.ActivityParty"
                   },
                   "PartyId":{  
                      "__metadata":{  
                         "type":"Microsoft.Crm.Sdk.Data.Services.EntityReference"
                      },
                      "Id":"9eab7a63-76fb-4d66-b57d-60093b98431b",
                      "LogicalName":"systemuser",
                      "Name":"Jason Lattimer"
                   }
                },
                {  
                   "__metadata":{  
                      "uri":"https://test.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/ActivityPartySet(guid'db45d614-ec22-e411-8f50-6c3be5a60c50')",
                      "type":"Microsoft.Crm.Sdk.Data.Services.ActivityParty"
                   },
                   "PartyId":{  
                      "__metadata":{  
                         "type":"Microsoft.Crm.Sdk.Data.Services.EntityReference"
                      },
                      "Id":"e316c71e-2218-e411-8f50-6c3be5a60c50",
                      "LogicalName":"account",
                      "Name":"XYZ"
                   }
                },
                {  
                   "__metadata":{  
                      "uri":"https://test.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/ActivityPartySet(guid'dc45d614-ec22-e411-8f50-6c3be5a60c50')",
                      "type":"Microsoft.Crm.Sdk.Data.Services.ActivityParty"
                   },
                   "PartyId":{  
                      "__metadata":{  
                         "type":"Microsoft.Crm.Sdk.Data.Services.EntityReference"
                      },
                      "Id":"81be3c55-2218-e411-8f50-6c3be5a60c50",
                      "LogicalName":"account",
                      "Name":"XYZ, LLC"
                   }
                },
                {  
                   "__metadata":{  
                      "uri":"https://test.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/ActivityPartySet(guid'5603aeb2-30f0-4180-b47b-f1017c99a09b')",
                      "type":"Microsoft.Crm.Sdk.Data.Services.ActivityParty"
                   },
                   "PartyId":{  
                      "__metadata":{  
                         "type":"Microsoft.Crm.Sdk.Data.Services.EntityReference"
                      },
                      "Id":"9eab7a63-76fb-4d66-b57d-60093b98431b",
                      "LogicalName":"systemuser",
                      "Name":null
                   }
                }
             ]
          }
       }
    }


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Wednesday, August 13, 2014 1:22 PM
    Moderator
  • That's very helpful, but I did ask if it was possible using the SOAP interface :)
    Wednesday, August 13, 2014 1:38 PM
  • You should check out the SoapLogger project in the SDK to convert a request from .NET into the SOAP equivalent.

    <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
      <s:Body>
        <Retrieve xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
          <entityName>phonecall</entityName>
          <id>d945d614-ec22-e411-8f50-6c3be5a60c50</id>
          <columnSet xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
            <a:AllColumns>false</a:AllColumns>
            <a:Columns xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
              <b:string>to</b:string>
            </a:Columns>
          </columnSet>
        </Retrieve>
      </s:Body>
    </s:Envelope>

    In the response you'd see:

    <a:KeyValuePairOfstringanyType>
      <b:key>partyid</b:key>
      <b:value i:type="a:EntityReference">
    	<a:Id>e316c71e-2218-e411-8f50-6c3be5a60c50</a:Id>
    	<a:LogicalName>account</a:LogicalName>
    	<a:Name>XYZ</a:Name>
      </b:value>
    </a:KeyValuePairOfstringanyType>


    Jason Lattimer
    My Blog -  Follow me on Twitter -  LinkedIn

    Wednesday, August 13, 2014 4:08 PM
    Moderator
  • That's genius!  I don't use .NET so I don't use the SDK.  I'll try out that request and see if it works.  Thanks!
    Thursday, August 14, 2014 2:08 PM
  • It works.  I'm really starting to have the overly-verbose XML being sent back from the API!  But what else should be expected from Microsoft :)
    Friday, August 15, 2014 8:39 AM