As a first step, add references to the latest version 9 assemblies
https://www.nuget.org/packages/Microsoft.CrmSdk.CoreAssemblies/
In the below sample code, we are creating an Auto number attribute in Contact Entity.
This is how the fields shows up inside contact form.
Using UpdateAttribute Request we can update the format for the AutoNumber field.
And also, we can have multiple auto number fields for an entity as shown below.
Sample Code
CreateAttributeRequest createAttributeRequest = new CreateAttributeRequest(); createAttributeRequest.EntityName = "contact"; var autoNumberAttributeMetadata = new StringAttributeMetadata() { AutoNumberFormat = "Auto Number - {SEQNUM:4} - {RANDSTRING:4} - {DATETIMEUTC:yyyyMMddhhmmss}", SchemaName = "new_autonumber1", MaxLength = 100, RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.ApplicationRequired), DisplayName = new Microsoft.Xrm.Sdk.Label("My Auto Number", 1033), Description = new Microsoft.Xrm.Sdk.Label("This is my first auto number field through SDK", 1033) }; createAttributeRequest.Attribute = autoNumberAttributeMetadata; var response = organizationService.Execute(createAttributeRequest);
And now the simplest and best way to create these Auto Number fields à
Using Auto Number Manager developed by Jonas Rapp, Microsoft MVP.
https://www.linkedin.com/pulse/auto-number-attributes-microsoft-dynamics-365-jonas-rapp/
https://github.com/MscrmTools/XrmToolBox
Hope it helps..
We are currently based in Pakistan and our D365 online servers are deployed in Europe. we need to create auto number with datetime sequence added. Hoever only option available is DATETIMEUTC. But UTC always create date & time with 5 hours difference, hence resulting wrong sequence. If there is any way to overcome this issue.
LikeLike
Hello,
Just wondering if using xrmtoolbox to generate the number, what do I need to do to include it in the solution so I can import it to another environment? Thanks.
LikeLike
Nothing Mark. It makes this change at the meta data level. It is just like creating a new field, so when you are moving the entity/field it will move along with it as part of solution.
LikeLike