I generate a record with the help of workflow in time out condition on every month particular date but my auto number code create duplicate number. using lock in my code also not help me...
*This post is locked for comments
I generate a record with the help of workflow in time out condition on every month particular date but my auto number code create duplicate number. using lock in my code also not help me...
*This post is locked for comments
Hi Arpit,
I think the problem is that you are using time out in condition in your Workflow. Auto number creation is one of the hardest thing to achieve.
I think this can help you: powerapps.microsoft.com/.../autonumber-fields-are-now-supported-by-the-modern-entity-designer
message: create
On Post Operation and Try with Pre Validation but it give error :The requested record was not found or you do not have sufficient permissions to view it
Could you please share what message this plugin is registered to? Is it on Post Operation or Pre Validation?
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;
using System.Threading;
namespace ClientAutonumberID
{
public class Autonumber : IPlugin
{
DateTime Newinvoicegenerationdate;
string Prefix, ID = "";
int _invoiceID = 0;
Entity ObjRegistration = new Entity();
Entity ObjConfig = new Entity();
static object locker = new object();
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);
lock (locker)
{
Thread.Sleep(1000);
Entity Invoiceobj = service.Retrieve(context.PrimaryEntityName, context.PrimaryEntityId, new ColumnSet(true));
QueryExpression Configuration_Q = new QueryExpression("new_configuration");
Configuration_Q.ColumnSet = new ColumnSet("new_invoiceprefix", "new_invoiceid");
EntityCollection ConfigurationColl = service.RetrieveMultiple(Configuration_Q);
if (ConfigurationColl.Entities.Count > 0)
{
ObjConfig = ConfigurationColl.Entities[0];
if (ObjConfig.Contains("new_invoiceprefix"))
{
Prefix = ObjConfig.GetAttributeValue<string>("new_invoiceprefix");
}
else
throw new Exception("Prefix is not Present");
if (ObjConfig.Contains("new_invoiceid"))
{
_invoiceID = ObjConfig.GetAttributeValue<Int32>("new_invoiceid");
}
else
throw new Exception("invoiceid is not Present");
string _idmonth = DateTime.Now.Month.ToString();
string _year = DateTime.Now.Year.ToString();
ID = Prefix + "/" + _year + "/" + _idmonth + "/" + _invoiceID.ToString();
_invoiceID++;
Invoiceobj.Attributes["new_name"] = ID;
ObjConfig.Attributes["new_invoiceid"] = _invoiceID;
Thread.Sleep(1000);
service.Update(Invoiceobj);
service.Update(ObjConfig);
}
}
}
}
}
Please make sure your lock object is static
eg: private static readonly object LockExecution = new object();
lock (LockExecution)
{
//Auto number code
}
Could you please share the details about entity and the auto numbering tool/code you are using?
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,214 Most Valuable Professional
nmaenpaa 101,156