Boolean attribute meta data in CRM4 to CRM 2011 C#

Posted on Posted in CRM 2011 SDK, Microsoft, MS CRM 2011, MS Dynamics, MS Dynamics CRM

In CRM 4 API to assign and save value of a boolean type attribute we had to call an object BooleanAttributeMetadata and then create an instance of it to assign values.

Here is a sample code of CRM4 SDK in C#


BooleanAttributeMetadata attribute = new BooleanAttributeMetadata();

attribute.FalseOption = new Option();

attribute.FalseOption.Label = CreateSingleLabel(falseCaption, locale);
attribute.FalseOption.Value = new CrmNumber();
attribute.FalseOption.Value.Value = 0;
attribute.TrueOption = new Option();
attribute.TrueOption.Label = CreateSingleLabel(trueCaption, locale);
attribute.TrueOption.Value = new CrmNumber();
attribute.TrueOption.Value.Value = 1;
attribute.DefaultValue = defaultValue;


 

If you are removing CRM 4 SDK and upgrading to CRM 2011 SDK or CRM 2013 SDK then you need to reference it to required libraries and change code to assign it to lable and OptionMetaData

Below is a sample code of assiging boolean meta data values in CRM 2011 SDK

 


BooleanAttributeMetadata attr = new BooleanAttributeMetadata
{
DisplayName = new Label(displayName, locale),
Description = new Label(displayName, locale),
OptionSet = new BooleanOptionSetMetadata(
new OptionMetadata(new Label(“True”, locale), 1),
new OptionMetadata(new Label(“True”, locale), 0)
)};


 

Once we have above values we call OrganizationServiceProxy.Execute and pass above object save values.