web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Contact reference number with prefix

(0) ShareShare
ReportReport
Posted on by 10

Is it possible for a field to generate a customer reference number with a prefix for the business for example. Business is PAS Consultancy and I want clients to have a "PAS123456" reference that is searchable

Do i need to get an external plugin or is the functionality possibly OOB?

Thanks in advance

I have the same question (0)
  • Verified answer
    shivaram Profile Picture
    3,315 on at

    Hi,

    There is a tool Auto Number Manager in Xrm Tool box and you can setup and it will generate reference number

    pastedimage1645516816593v1.png

  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    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/

  • Suggested answer
    Paul Speakman Profile Picture
    10 on at

    brilliant - thank you for the guidance!

  • Paul Speakman Profile Picture
    10 on at

    interesting - ill have a look, thank you!

  • Verified answer
    Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi,

    Another approach is to create auto number attribute in CRM with sequential 6 digit format -

    docs.microsoft.com/.../autonumber-fields

    6675.CR43.PNG

    Then create Real Time workflow to update the auto nuber field with Business Prefix value -

    5661.CR44.PNG

    Result -

    1067.CR45.PNG

    Please mark my answer verified if this is helpful!

    Regards,

    Bipin Kumar

    Follow my Blog: xrmdynamicscrm.wordpress.com/

  • Suggested answer
    Paul Speakman Profile Picture
    10 on at

    this is the one!! thanks very much for this

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 170 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 61

#3
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 52 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans