Home > CRM > [Step by Step] Using ADX Auto Numbering Solution In Plug-ins

[Step by Step] Using ADX Auto Numbering Solution In Plug-ins

As we know with Dynamics 365 for CE 9.0 release, we can add an auto-number attribute for any entity programmatically.

Prior to Dynamics 9.0, ‘AdxstudioAutoNumberingWorkflowHelper’ solution is one of the options to implement auto numbering.

Lets see how to use this solution and generate auto number on Case entity.

What does AdxstudioAutoNumberingWorkflowHelper solution contain?

  • AdxstudioAutoNumberingWorkflowHelper solution contain 2 key components
  • AN_8
    • ‘Auto Numbering Definition’ entity – Where you define auto numbering pattern.
    • ‘Adxstudio.Xrm.Workflow.AutoNumberHelper’ custom workflow – Which generates the Auto number as per the configurations made in ‘Auto Numbering Definition’ entity

Below are the high level steps:

  • Download and Install ADX solution and configure ‘Auto Number Definition’.
  • Create a new ‘Action’ which calls Adx Auto Number Workflow.
  • Trigger ‘Action’ from ‘Plugin’

Install ADX solution and configure Definition:

  • Download and install the solution.
  • Once the solution is installed you would get Sitemap node as below under ‘Settings’.


  • Create a record in ‘Auto Numbering Definition’ entity and set below fields
  • AN_3
    • Name – Can be anything. ‘Name’ has to be passed as parameter to the ‘Adxstudio.Xrm.Workflow.AutoNumberHelper’ workflow
    • Format – Pattern of Auto number
    • Digits – Length of your auto number digits.

Create a new ‘Action’ which calls Adx Auto Number Workflow:

Best way to trigger workflow from Plug-in is by creating an ‘Action’

  • Create a new ‘Action’
  • Add 2 parameters
    • ‘NumberDefintion’ – Input : We use this to pass ‘Auto Numbering Definition’ Name
    • AutoNumber – Output : We use this to capture the generated  ‘Auto Number’
  • Add 2 steps to the ‘Action’
    • Step 1 – Trigger ‘Adxstudio Workflow Helpers:Get Auto-Number’  with below PropertiesAN_2
    • Step 2 – Capture the generated Auto Number using ‘Assign Value:’ step with below Properties


  • Overall ‘Action’ looks as below


  • Activate the ‘Action’

Trigger ‘Action’ from ‘Plugin’:

  • Below is the code to execute the ‘Action’ by passing Parameter and read the ‘Auto Number’

var context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
var serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
var svc = serviceFactory.CreateOrganizationService(context.UserId);

if (context.InputParameters.Contains(“Target”) && context.InputParameters[“Target”] is Entity) {
var entCase = context.InputParameters[“Target”] as Entity;

// Logic to trigger Custom Action which trigger ADX Auto Number WF
// Pass your Custom Action Name (i.e., raj_TriggerADXAutoNumber in my case)
var orgRequest = new OrganizationRequest(“raj_TriggerADXAutoNumber”);
// Pass ‘Auto Number Definition Name’ you configured in system
orgRequest[“NumberDefinition”] = “Case Auto Number”;

// Execute the request
OrganizationResponse response = svc.Execute(orgRequest);
string autoNumber = response.Results[“AutoNumber”].ToString();

// Set generated auto number to Case’s Title field
entCase[“title”] = autoNumber;

  • Register the Plug-in on ‘PreCaseCreate’
  • Create a Case and you would get the number set on ‘Title’ field







  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: