Creating a auto number field has always been part of a project somewhere along the line and now we can create them using Dynamics 365 SDK without having to write custom plugins.
At the time of writing the post we can only create auto number fields using the SDK and not from the UI but i am positive we will see the feature in the UI in the near future.
Currently supported tokens
- Static String
- DATETIME:[format] e.g: yyyyMMddhhmmss
- SEQNUM:size
- RANDSTRING:6
Example:
The following examples show how to create a new auto-number attribute named new_SerialNumber for a custom entity named new_Widget which will have a value that looks like this: WID-00001-AB7LSFG-20170913070240. Using the Organization service with SDK assemblies CreateAttributeRequest and StringAttributeMetadata classes:
CreateAttributeRequest widgetSerialNumberAttributeRequest = new CreateAttributeRequest { EntityName = "newWidget", Attribute = new StringAttributeMetadata { //Define the format of the attribute AutoNumberFormat = "WID-{SEQNUM:5}-{RANDSTRING:6}-{DATETIMEUTC:yyyyMMddhhmmss}", LogicalName = "new_serialnumber", SchemaName = "new_SerialNumber", RequiredLevel = new AttributeRequiredLevelManagedProperty(AttributeRequiredLevel.None), MaxLength = 100, // The MaxLength defined for the string attribute must be greater than the length of the AutoNumberFormat value, that is, it should be able to fit in the generated value. DisplayName = new Label("Serial Number", 1033), Description = new Label("Serial Number of the widget.", 1033) } }; _serviceProxy.Execute(widgetSerialNumberAttributeRequest);
Microsoft Docs used click here
*This post is locked for comments