While retrieving data for a particular entity and displaying it in a Silverlight web resource I found that for option sets values it was displaying the numeric value of the option set that is stored in the entity and not the display text. In order for the display value I had to retrieve the metadata of the option set. Retrieving metadata can be done by calling the OrganizationService of CRM. Now retrieving metadata using organization service is not the same as using Microsoft.Xrm.Sdk dll’s or the QueryExpression class that we use in plugins. The one simple reason being that Microsoft.Xrm.Sdk.dll’s are not compatible with Silverlight. So in the code below you will find the alternative way to query the organizationservice in Silveright web resource.
//Make sure you add the "/web" to the organization url for silverlight web resource.
Uri serviceUrl = new Uri("http://crm.microsoft.com/Contoso/XRMServices/2011/Organization.svc/web");
BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.None)
{
MaxReceivedMessageSize = int.MaxValue,
MaxBufferSize = int.MaxValue,
SendTimeout = TimeSpan.FromMinutes(2)
};
OrganizationServiceClient client = new OrganizationServiceClient(binding, new EndpointAddress(serviceUrl));
OrganizationRequest request = new OrganizationRequest
{
RequestName = "RetrieveAttribute",
Parameters = new ParameterCollection
{
new KeyValuePairOfstringanyType
{key = "EntityLogicalName", value = "new_address"},
new KeyValuePairOfstringanyType
{key = "LogicalName", value = "new_addresstype"},
new KeyValuePairOfstringanyType
{key = "MetadataId", value = Guid.Empty},
new KeyValuePairOfstringanyType
{key = "RetrieveAsIfPublished", value = false}
}
};
//register the async completed event.
client.ExecuteCompleted += ClientAddressTypeExecuteCompleted;
client.ExecuteAsync(request);
Please writeback in case of any queries.
Posted by yukitaka ohta on August 30, 2011 at 10:48 am
nice! iwanted this info.
and tell me about namespace for this code.
System.ServerModel and and … Microsoft.Xrm.Sdk ????
Posted by Sayantan Samanta on September 4, 2011 at 11:37 am
Thats the sad part….silverlight does not take in System.ServiceModel version 4.0. If you try adding System.ServiceModel it accepts only version 2.0.
Silverlight is also not compatible with Microsoft.Xrm.Sdk since these assemblies are not built against the silverlight runtime.
So the only option remains is hard code your parameters as strings as shown in my post.
thanks for asking question yukitaka!!!
Posted by ota2000 on September 7, 2011 at 9:26 am
OK, throw out the past. get in the future…
latest SDK walkthrough was a good cooking space for me.
“Use the SOAP Endpoint for Web Resources with Silverlight” was my study place in this week.
in this sample code you can get optionset’s value and label with only adding attribute name. like this…
Columns = new System.Collections.ObjectModel.ObservableCollection(new string[] { “name”, “address1_addresstypecode” })
“name” is original one, “address1_addresstypecode” is optionset type attribute.
then you will see the label text just i checked by fiddler xml display.
and i found the label text not in attributevalues but in formattedvalues.
then code like…
entity.FormattedValues[0].Value // not using GetAttributeValue
you find [0] ? it’s array, if you chose more optionset, you should check what text is.
entity.FormattedValues[0].Key // use this.
value was little complicated.
OptionSetValue myValue = entity.GetAttributeValue(“address1_addresstypecode”)
myValue.Value // this is optionset value
this sample solution has class file then no hard code need.
maybe usefull crmsvcutil.exe in \sdk\bin directory make class file for you.
again you don’t need hard code.
conclusion
1.SOAP endpoint programing provides optionset label text very easily but microsoft provide less document. very sad situation.
2.optionset on a Form is more easy. Xrm.PageScript library can handle it. and it can call from silverlight programs.
3.if you want to make a entity definition sheet or metadatabrowser like tool. only these purpose, look metadata.
me the last comer of this field but no old thing and get new info.
anyway your blog was my start point.
thank you.
Posted by Xitij Thool on February 7, 2012 at 10:16 am
Is is possible to get all the Attribute metadata instead of specifying the attributes individually.