Hi Sougata,
1. Download plugin registration tool:
https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/download-tools-nuget
2. Follow tutorial below to create a VS project and register it as plugin.
https://carldesouza.com/creating-dynamics-crm-plugin-from-scratch/
3. My sample code for auto number, it uses Random class to generate auto number between 100000 to 999999, and will be trigger on creation of Account entity.
You can need to replace crfe2_companyid parameter of this line "entity.Attributes.Add("crfe2_companyid", number);" with logical name of your own numeric field.
(And change the target entity to Case for your situation.)
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
using System;
using System.Text;
namespace DynamicsPlugins
{
public class plugin2 : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IOrganizationServiceFactory servicefactory =
(IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service =
servicefactory.CreateOrganizationService(context.UserId);
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
if (entity.LogicalName != "account")
{
return;
}
if (context.Depth > 2)
{
tracingService.Trace("Context depth is: {0}", context.Depth);
return;
}
try
{
if (entity.Attributes.Contains("name"))
{
Random rnd = new Random();
int number = rnd.Next(100000, 1000001);
entity.Attributes.Add("crfe2_companyid", number);
}
}
catch (Exception ex)
{
tracingService.Trace("Error of Plugin: {0}", ex.ToString());
throw;
}
}
}
}
}


Additionally, we can also create an auto number field in OOB way:
https://gestisoft.com/en-ca/how-to-create-auto-number-fields-in-dynamics-365/
Or running a console application to do it:
https://passion4dynamics.com/tag/create-auto-number-field-using-c/
Regards,
Clofly