Enable/Disable audit in Attribute MS-CRM (C#.NET)
Views (801)
To connect CRM check my blog here
To Create audit-able Entity check my blog here
Only Code No Talks
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Messages;
using Microsoft.Xrm.Sdk.Metadata;
using Microsoft.Xrm.Tooling.Connector;
using System;
using System.Configuration;
namespace CreateAuditAttributeBlog
{
class Program
{
static void Main(string[] args)
{
string entityName = "new_adviser";
CrmServiceClient crmServiceClientObj = new CrmServiceClient(ConfigurationManager.ConnectionStrings["CrmOnlineStringFromAppConfig"].ConnectionString);
if (!crmServiceClientObj.IsReady)
{
Console.WriteLine("No Connection was Made.");
return;
}
Console.WriteLine("Connected");
AttributeMetadata At = new StringAttributeMetadata()
{
// Set base properties
SchemaName = "new_AdviserAttr",
DisplayName = new Label("Adivsor Code Name", 1033),
RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
Description = new Label("Adivsor Code Name string attribute", 1033),
MaxLength = 100,
IsAuditEnabled = new BooleanManagedProperty(true)//
};
// Create the request.
CreateAttributeRequest createAttributeRequest = new CreateAttributeRequest
{
EntityName = entityName,
Attribute = At
};
// Execute the request.
crmServiceClientObj.Execute(createAttributeRequest);
/*
NOTE : YOU DONT HAVE TO PUBLISH OR CALL PUBLISH WHILE CREATING ENTITY OR UPDATING ENTITY.
*/
Console.WriteLine("Created the attribute {0}.", At.SchemaName);
Console.ReadLine();
}
}
}

Like
Report
*This post is locked for comments