Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested answer

How can I create a field that is a 6-digit randomly generated unique GUID in CRM?

(0) ShareShare
ReportReport
Posted on by

Hello,

How can I create a custom field that is a 6-digit (or 6 character) randomly generated unique GUID in CRM?

Thanks!

  • Suggested answer
    Ak Negi Profile Picture
    320 on at
    RE: How can I create a field that is a 6-digit randomly generated unique GUID in CRM?

    For this you can use third party Auto Number solution or develop own Auto number  via plugin or follow this OOB functionality https://docs.microsoft.com/en-us/dynamics365/customerengagement/on-premises/developer/create-auto-number-attributes...

  • Fubar Profile Picture
    2,752 on at
    RE: How can I create a field that is a 6-digit randomly generated unique GUID in CRM?

    Autonumber is available in the new Interface (PowerApps/Flow Interface), or use XrmToolBox (there is plugin to set the autonumber), or you can enable the Autonumber via .Net code (but this is already done for you in XrmToolBox).

    See the following link for general format supported and code examples

    docs.microsoft.com/.../create-auto-number-attributes

  • Community Member Profile Picture
    on at
    RE: How can I create a field that is a 6-digit randomly generated unique GUID in CRM?

    Thanks!  It doesn't necessarily need to be a GUID, I just want it to create a randomized 6-character ID using alphanumeric characters when the record is created.

  • Suggested answer
    Martin Donnelly Profile Picture
    1,030 on at
    RE: How can I create a field that is a 6-digit randomly generated unique GUID in CRM?

    Oops!  I didn't notice the guid part of the question.  There is no such thing as a 6-digit Guid.  They are 32 (plus hyphens.) 00000000-0000-0000-0000-000000000000

  • Martin Donnelly Profile Picture
    1,030 on at
    RE: How can I create a field that is a 6-digit randomly generated unique GUID in CRM?

    I can't get my hands on the link right now but, there is a new feature that hasn't made it to the user interface yet allows you to create auto generated value fields.  The six-character seems to go A9A9A9 -- alpha/numeral chain of 3.  Here's the class I put together.  You may want to search on some of the more unusual terms to find sources of greater explanation:

    using System;
    using System.Configuration;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    using Microsoft.Xrm.Sdk.Messages;
    using Microsoft.Xrm.Sdk.Metadata;
    using Microsoft.Xrm.Tooling.Connector;
    using System.Collections;
    
    namespace consoleUtility {
        class AutonumberingFieldMaker {
            public AutonumberingFieldMaker(Microsoft.Xrm.Sdk.IOrganizationService CRMservice) {
                this.service = CRMservice;
            }
    
            private Microsoft.Xrm.Sdk.IOrganizationService service;
            private StringAttributeMetadata attributeMetadata = null;
    
            private string nbrFormat = null;
            public string AutonumberingFormat { set { nbrFormat = value;
                    buildAttributeMetadata();
                } get { return nbrFormat; } }
            private string sname = null;
            public string SchemaName { set { sname = value; attributeMetadata = buildAttributeMetadata(); } get { return sname; } }
            private string dname = null;
            public string DisplayName { set { dname = value; attributeMetadata = buildAttributeMetadata(); } get { return dname; } }
            private int? len = null;
            public int? MaxLength { set { len = value; attributeMetadata = buildAttributeMetadata(); } get { return len; } }
            private string desc = null;
            public string Description { set { desc = value; attributeMetadata = buildAttributeMetadata(); } get { return desc; } }
    
            private StringAttributeMetadata buildAttributeMetadata() {
                if (null != nbrFormat && null != sname && null != dname && null != len) { 
                    StringAttributeMetadata am = new StringAttributeMetadata() {
                        AutoNumberFormat = this.nbrFormat,
                        SchemaName = this.sname,
                        LogicalName = this.sname.ToLower(),
                        FormatName = StringFormatName.Text,
                        RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None),
                        DisplayName = new Microsoft.Xrm.Sdk.Label(this.dname, 1033),
                        IsAuditEnabled = new Microsoft.Xrm.Sdk.BooleanManagedProperty(false),
                        IsGlobalFilterEnabled = new Microsoft.Xrm.Sdk.BooleanManagedProperty(false),
                        MaxLength = len
                    };
                    if (null!=desc)
                        am.Description = new Microsoft.Xrm.Sdk.Label(desc, 1033);
                    return am;
                }
                return null;
            }
    
            public void CreateIn(string entityLogicalName) {
                if (null!=attributeMetadata) {
                    CreateAttributeRequest req = new CreateAttributeRequest() {
                        EntityName = entityLogicalName,
                        Attribute = attributeMetadata
                    };
                    service.Execute(req);
                }
            }
        }
    }
    

    here's how I ran it twice:

    AutonumberingFieldMaker cmAddr = new AutonumberingFieldMaker(CrmService);
    
    cmAddr.AutonumberingFormat = "a{RANDSTRING:6}";
    cmAddr.Description = "Autogenerated address number";
    cmAddr.DisplayName = "adnbr";
    cmAddr.SchemaName = "new_adnbr";
    cmAddr.MaxLength = 8;
    cmAddr.CreateIn("customeraddress");
    
    cmAddr.AutonumberingFormat = "c{RANDSTRING:6}";
    cmAddr.Description = "Autogenerated account number";
    cmAddr.DisplayName = "cmAddr";
    cmAddr.SchemaName = "new_cmAddr";
    cmAddr.MaxLength = 8;
    cmAddr.CreateIn("account");

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 78 Super User 2025 Season 1

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 47

Overall leaderboard

Product updates

Dynamics 365 release plans