Hi,
When I am try to generate autonumber.so i will wrote like this but it is not triggered then i will try to debug through profile then i have error.
And this is my code.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
namespace CRMPluginProject1
{
public class Class1 : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
ITracingService tracer = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = factory.CreateOrganizationService(context.UserId);
try
{
Entity entity = (Entity)context.InputParameters["Target"];
QueryExpression stu = new QueryExpression("kbitsol_student");
stu.ColumnSet = new ColumnSet("kbitsol_name");
EntityCollection res = service.RetrieveMultiple(stu);
int totalreocrds = res.Entities.Count;
var finalrecord = totalreocrds + 1;
string prefix = "STU-DAV-00";
entity.Attributes["kbitsol_name"] = prefix + finalrecord;
}
catch (Exception ex)
{
Console.WriteLine("Autonumber Plugin not executed" + ex);
Console.ReadLine();
}
}
}
}
So please help.
*This post is locked for comments