1

The CRM has some customized option sets, for example, Salutation option set is defined for Contact entity. I need to get values of this option set when creating or updating contacts. I tried to use RetrieveOptionSet request to get the option set values as below:

SOAP action to use http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute

SOAP request body

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
            <request i:type="a:RetrieveOptionSetRequest" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
               <a:Parameters xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
                  <a:KeyValuePairOfstringanyType>
                      <b:key>MetadataId</b:key>
                      <b:value i:type="c:guid" xmlns:c="http://schemas.microsoft.com/2003/10/Serialization/">00000000-0000-0000-0000-000000000000</b:value>
                  </a:KeyValuePairOfstringanyType>
                  <a:KeyValuePairOfstringanyType>
                      <b:key>RetrieveAsIfPublished</b:key>
                      <b:value i:type="c:boolean" xmlns:c="http://www.w3.org/2001/XMLSchema">true</b:value>
                  </a:KeyValuePairOfstringanyType>
                  <a:KeyValuePairOfstringanyType>
                      <b:key>Name</b:key>
                      <b:value i:type="c:string" xmlns:c="http://www.w3.org/2001/XMLSchema">my_type</b:value>
                  </a:KeyValuePairOfstringanyType>
               </a:Parameters>
               <a:RequestId i:nil="true" />
               <a:RequestName>RetrieveOptionSet</a:RequestName>
            </request>
        </Execute>
    </s:Body>
</s:Envelope>

The problem is that I can only use this request to get global option sets, but for customized option sets, this request just returns a not found error.

Does anyone knows how to get customized option set values?

EDIT: I'm using Java client to access Dynamics CRM web service. This is the final SOAP request body I used to successfully get option set values.

<s:Envelope>
  <s:Body>
    <Execute>
      <request i:type="a:RetrieveAttributeRequest">
        <a:Parameters>
          <a:KeyValuePairOfstringanyType>
            <b:key>MetadataId</b:key>
            <b:value i:type="c:guid">00000000-0000-0000-0000-000000000000</b:value>
          </a:KeyValuePairOfstringanyType>
          <a:KeyValuePairOfstringanyType>
            <b:key>RetrieveAsIfPublished</b:key>
            <b:value i:type="c:boolean">true</b:value>
          </a:KeyValuePairOfstringanyType>
          <a:KeyValuePairOfstringanyType>
            <b:key>EntityLogicalName</b:key>
            <b:value i:type="c:string">contact</b:value>
          </a:KeyValuePairOfstringanyType>
          <a:KeyValuePairOfstringanyType>
            <b:key>LogicalName</b:key>
            <b:value i:type="c:string">my_type</b:value>
          </a:KeyValuePairOfstringanyType>
        </a:Parameters>
        <a:RequestId i:nil="true"/>
        <a:RequestName>RetrieveAttribute</a:RequestName>
      </request>
    </Execute>
  </s:Body>
</s:Envelope>

The sample code in this page gave me useful information.

pnuts
  • 58,317
  • 11
  • 87
  • 139
Fu Cheng
  • 3,385
  • 1
  • 21
  • 24

2 Answers2

2

You need to use the RetrieveAttributeRequest, not the RetrieveOptionSetRequest.

The metadata for non-global(local) optionsets are defined as a part of the attribute on the entity itself, rather than as an entirely different structure. ie. if you delete your local optionset attribute from your entity, you lose all of the entire option set definition. But if it's a global optionset, deleting an attribute on a entity the references doesn't result in any loss of data for the option set

Daryl
  • 18,592
  • 9
  • 78
  • 145
  • Can we use this JS method for accessing some external data, basically we need to add option set dynamically (which are not present in optionset values in CRM system). Something similar to what is done in DependentOptionSet JS, we are getting XML from other source? – Ashish Jain Dec 19 '13 at 13:05
  • @AshishJain so basically you're wanting to pretend that there are values in an OptionSet, that isn't actually in the OptionSet? – Daryl Dec 19 '13 at 16:00
  • Basically my detailed query is at http://stackoverflow.com/questions/20658554/crm-2013-dynamic-optionset-issue/20658857#20658857 If it is helpful. – Ashish Jain Dec 19 '13 at 17:17
1

I think your question was answered a couple of months ago in this link:

Dynamics CRM - Accessing Custom Product Option Value

Please let me know if it is not the same, and we will try to find another way ;)

But thinking about you requirement again, and if I have understand it properly, how often is that option set going to change? Why don't you just retrieve the optionsets with the crmsvcutil.exe from the SDK?

Cheers,

Mario

Community
  • 1
  • 1
  • Since the op is working directly in SOAP, I would assume he is either using javascript or something else besides .NET, which is what the answer on your link is in. – Daryl Jun 28 '13 at 13:09
  • I just didn't want anyone to close it since the questions are so similar. + 1 for finding the link though... – Daryl Jun 28 '13 at 13:32
  • I'm using Java to retrieve these options. – Fu Cheng Jun 30 '13 at 21:39