Share via


Do fast customization with metaservice

How many times haven’t you added your customer enmities or attributes with the CRM tools? They are all good but if you are an expert why do not take your customization experience one step further? The Metadata Service Web service contains the messages that you use to read or write the definitions for all the entities in a Microsoft Dynamics CRM installation. The metadata service exposes the same functionality as the web-based customization tools but again if you want to take your customization experience one step further. The Metadata Service Schema doesn’t change therefore your could use the proxy assemblies to access the functionality. Do not forget to include the namespaces

Microsoft.Crm.Sdk;
Microsoft.Crm.Sdk.Metadata;
Microsoft.Crm.SdkTypeProxy.Metadata;

            MetadataService meta = CrmServiceUtility.GetMetadataService("https://localhost:5555", "Stockholm");

            try

            {

                DateTimeAttributeMetadata date = new DateTimeAttributeMetadata();

                date.SchemaName = "new_FromDate";

                date.DisplayName = CrmServiceUtility.CreateSingleLabel("FromDate", 1053);

                date.RequiredLevel = new CrmAttributeRequiredLevel();

                date.RequiredLevel.Value = AttributeRequiredLevel.None;

                date.EntityLogicalName = EntityName.customerrelationship.ToString(); //Change to entity to add attribute on

                CreateAttributeRequest createAttribute = new CreateAttributeRequest();

                createAttribute.EntityName = EntityName.customerrelationship.ToString();

                createAttribute.Attribute = date;

                meta.Execute(createAttribute);

//Add code to publish or do publish all manual in webGUI

            }

            catch (System.Web.Services.Protocols.SoapException ex)

            {

  Console.WriteLine("Request Failed.\n {0}", ex.Message);

                Console.WriteLine();

            }

The above example code doesn’t work since the entity I tried to add the custom field doesn’t support customizations. My basic tough was to add a date field on the Relationship entity by using the metaservice since you don’t have the choice in web GUI. Unfortunately it didn’t work L But if you change to another customable entity it all works fine. I also used the Crm SDK 4.07 CrmServiceUtlity.cs file as ref