Richard
Richard

Reputation: 53

Dynamics 365 implementation auto number with plugin

I have already implement auto number with plugin, and it is through another entity type to ensure all operations are in one transaction. but I have another question, that is can we use process lock(eg. mutex) to fix it? this will more flexible than before, isn't it?

Upvotes: 0

Views: 1303

Answers (2)

Alex
Alex

Reputation: 23300

Dynamics 365 has native support for auto-numbering fields since v9.0, with the minor inconvenience of having to manipulate them through code only. Unless it's a broken feature (it happens), there's no need for custom autonumbers anymore.

https://learn.microsoft.com/en-us/dynamics365/customer-engagement/developer/create-auto-number-attributes

Example:

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);

Docs point out that

The sequential segment is generated by SQL and hence uniqueness is guaranteed by SQL.

XrmToolbox should have a plugin to manage auto number fields (thus making it easier), but I haven't tried it.

Upvotes: 1

James Wood
James Wood

Reputation: 17562

Plugin's can be run on multiple machines concurrently depending on your installation - that's why the entity (database) lock is regularly used.

Upvotes: 0

Related Questions