Skip to main content

Notifications

Announcements

No record found.

Customer experience | Sales, Customer Insights,...
Answered

Contact reference number with prefix

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

  • Suggested answer
    Paul Speakman Profile Picture
    Paul Speakman 10 on at
    RE: Contact reference number with prefix

    this is the one!! thanks very much for this

  • Verified answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Contact reference number with prefix

    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/

  • Paul Speakman Profile Picture
    Paul Speakman 10 on at
    RE: Contact reference number with prefix

    interesting - ill have a look, thank you!

  • Suggested answer
    Paul Speakman Profile Picture
    Paul Speakman 10 on at
    RE: Contact reference number with prefix

    brilliant - thank you for the guidance!

  • Verified answer
    Bipin D365 Profile Picture
    Bipin D365 28,964 Super User 2024 Season 1 on at
    RE: Contact reference number with prefix

    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/

  • Verified answer
    shivaram Profile Picture
    shivaram 3,315 on at
    RE: Contact reference number with prefix

    Hi,

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

    pastedimage1645516816593v1.png

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans