How to change metadata of a field ( display name, Audit setting, searchability etc.) using .Net code

How to change metadata of a field ( display name, Audit setting, searchability etc.) using .Net code


You will need to use RetrieveAttributeRequest and UpdateAttributeRequest to expose the metadata of the attribute. Once the entity is retrieved, you can change the various metadata and update it using SDK

Steps are given below:

Create a console application

Add reference to the CRM SDK Dlls

Add the following using statement:

using System;

using System.Runtime.InteropServices;

using Microsoft.Xrm.Sdk;

using Microsoft.Xrm.Sdk.Messages;

Connect to the CRM organisation

Retrieve the attribute using RetrieveAttributeRequest

// Create the request

var attributeRequest = new RetrieveAttributeRequest


                EntityLogicalName = “account”,

                LogicalName = “name”,

                RetrieveAsIfPublished = true


// Execute the request

var attributeResponse = (RetrieveAttributeResponse) _service.Execute(attributeRequest);

Console.WriteLine(“Retrieved the attribute {0}.”, attributeResponse.AttributeMetadata.SchemaName);

Modify the retrieved attribute

var retrievedAttributeMetadata = attributeResponse.AttributeMetadata;

retrievedAttributeMetadata.DisplayName = new Label(“Account Name”, 1033);

retrievedAttributeMetadata.IsValidForAdvancedFind = new BooleanManagedProperty(false);

retrievedAttributeMetadata.IsAuditEnabled = new BooleanManagedProperty(false);

Update the retrieved attribute

// Update an attribute retrieved via RetrieveAttributeRequest

var updateRequest = new UpdateAttributeRequest


                Attribute = retrievedAttributeMetadata,

                EntityName = “account”,

                MergeLabels = false


// Execute the request


Console.WriteLine(“Updated the attribute {0}.”, retrievedAttributeMetadata.SchemaName);

 2,364 total views,  1 views today

About Author

Ricky Saini

Ricky Saini
Dynamics CRM, SharePoint, Office 365, Windows Azure and .Net Architect/Consultant/Freelancer in Australia ( Melbourne, Sydney and Canberra)

Leave a Comment