Hi,
Kindly below code for auto number and it shows error on red mark text.
using System;
using System.ServiceModel;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Query;
namespace crmpackageplugin.accautonumber
{
public class autonumberplugin :IPlugin
{
public void execute(IServiceProvider serviceprovider)
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceprovider.GetService(typeof(IPluginExecutionContext));
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"];
QueryExpression query = new QueryExpression("account");
query.ColumnSet = new ColumnSet(true);
EntityCollection result = service.RetrieveMultiple(query);
int totalrecords = result.Entities.Count;
var finalresult = totalrecords + 1;
int series = 1000;
entity.Attributes["new_autonumber"] = series + finalresult;
}
}
}
}
*This post is locked for comments