web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Blogs / Friyank’s blog / Enable/Disable audit in Att...

Enable/Disable audit in Attribute MS-CRM (C#.NET)

Friyank Profile Picture Friyank 944

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();
}
}
}


Comments

*This post is locked for comments