Hi,
Business is a field on your Entity where you want to generate customer reference number?
OOB auto number can only accept static value but in your case it should be dynamic based on Business field value. You will need to write your own plugin on Pre-operation to generate custom reference number based on the Business field value.
You can use copy below code for your plugin -
public void Execute(IServiceProvider serviceProvider)
{
// Obtain the execution context from the service provider.
Microsoft.Xrm.Sdk.IPluginExecutionContext context = (Microsoft.Xrm.Sdk.IPluginExecutionContext)
serviceProvider.GetService(typeof(Microsoft.Xrm.Sdk.IPluginExecutionContext));
// The InputParameters collection contains all the data passed in the message request.
if (context.InputParameters.Contains("Target") &&
context.InputParameters["Target"] is Entity)
{
// Obtain the target entity from the input parameters.
Entity entity = (Entity)context.InputParameters["Target"];
//</snippetAccountNumberPlugin2>
// Verify that the target entity represents an account.
// If not, this plug-in was not registered correctly.
if (entity.LogicalName == "account")
{
// An accountnumber attribute should not already exist because
// it is system generated.
if (entity.Attributes.Contains("accountnumber") == false)
{
// Create a new accountnumber attribute, set its value, and add
// the attribute to the entity's attribute collection.
Random rndgen = new Random();
entity.Attributes.Add("accountnumber", rndgen.Next().ToString());
}
else
{
// Throw an error, because account numbers must be system generated.
// Throwing an InvalidPluginExecutionException will cause the error message
// to be displayed in a dialog of the Web application.
throw new InvalidPluginExecutionException("The account number can only be set by the system.");
}
}
}
}
This plugin is written for account entity but you can modify this to prefix with Business field value.
Please mark my answer verified if this is helpful!
Regards,
Bipin Kumar
Follow my Blog: xrmdynamicscrm.wordpress.com/