Get OptionSet Label using FormattedValues property of Entity in Plugin in CRM

The easiest way to get the Label for the option set in plugin is using the FormattedValues property of the Entity.

The Post Create plugin on Contact record getting the label for the address type field.


if (context.InputParameters.Contains(“Target”) && 
context.InputParameters[“Target”] is Entity){

// Obtain the target entity from the input parmameters. 

Entity entity = (Entity) context.InputParameters[“Target”];

if(entity.Contains(“address1_addresstypecode”)){

string addressTypeCodeLabel = entity.FormattedValues[“address1_addresstypecode”];

entity.Attributes[“address1_city”] = addressTypeCodeLabel;

service.Update(entity);}

}

http://community.dynamics.com/crm/b/crmmitchmilam/archive/2013/04/18/crm-sdk-nugget-entity-formattedvalues-property.aspx

Hope it helps.


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

Share your thoughts

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