Retrieve OptionSet Lables using MsCrm 2011 SOAP Service in SilverLight

Retrieve OptionSet Lables using MsCrm 2011 SOAP Service in SilverLight

Follow the Below link to Add Class files to your Project “SilverlightExtensionMethods.cs ” and “SilverlightUtility.cs”

http://msdn.microsoft.com/en-us/library/gg594452.aspx

using System;

using System.Collections.Generic;

using System.Linq;

using System.Net;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Animation;

using System.Windows.Shapes;

using MsCrmSoapService.CrmSdk;

using System.Text;

namespace MsCrmSoapService

{

public partial class MainPage : UserControl

{

public MainPage()

{

InitializeComponent();

}

string lblStageValues;

private void OptionSetLabels(string entityName, string attributeName)

{

OrganizationRequest request = new OrganizationRequest();

request.RequestName = “RetrieveAttribute”;

request[“EntityLogicalName”] = “account”;

request[“LogicalName”] = “new_stage”;

request[“MetadataId”] = Guid.Empty;

request[“RetrieveAsIfPublished”] = true;

IOrganizationService service = SilverlightUtility.GetSoapService();

service.BeginExecute(request, new AsyncCallback(Callback), service);

}

private void Callback(IAsyncResult result)

{

this.Dispatcher.BeginInvoke(delegate()

{

try

{

StringBuilder sb = new StringBuilder();

OrganizationResponse response = ((IOrganizationService)result.AsyncState).EndExecute(result);

OptionSetMetadata optionSetMetadata = ((EnumAttributeMetadata)(response.Results[0].Value)).OptionSet;

foreach (OptionMetadata option in optionSetMetadata.Options)

{

lblStageValues = (sb.AppendLine(option.Label.UserLocalizedLabel.Label)).ToString();

}

}

catch (Exception ex)

{

}

});

}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s