Hello,
How can I create a custom field that is a 6-digit (or 6 character) randomly generated unique GUID in CRM?
Thanks!
Hello,
How can I create a custom field that is a 6-digit (or 6 character) randomly generated unique GUID in CRM?
Thanks!
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...
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
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.
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
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");
Daivat Vartak (v-9d...
225
Super User 2025 Season 1
Vahid Ghafarpour
78
Super User 2025 Season 1
Muhammad Shahzad Sh...
47