Create autonumber columns (Microsoft Dataverse) - Power Apps (2024)

  • Article
  • 4 minutes to read

With Microsoft Dataverse, you can add an autonumber column for any table. To create auto-number colums in Power Apps, see Autonumber columns.

This topic explains how you can programmatically create an autonumber column and set a seed value for sequential elements. In addition, the topic shows how to set the sequence number for the next record if you need to reset the seed at any time later.

Note

Unsure about entity vs. table? See Developers: Understand terminology in Microsoft Dataverse.

Note

The setting of the seed is optional. There is no need to call the seed if you don't need to reseed.

You can create an autonumber column in the same way you create a string column using the StringAttributeMetadata Class except that you use the AutoNumberFormat Property. Use the AutoNumberFormat property to define a pattern that includes sequential numbers and random strings by composing placeholders, which indicates the length and type of values that are generated. The random strings help you to avoid duplicates or collisions, especially when offline clients trying to create autonumbers.

When creating an autonumber column, the FormatName Property or the Format Property values must be Text. Since these are the default values you will typically not set this property. You cannot create an autonumber column that uses any other special kind of format such as Email, Phone, TextArea, Url or any other existing formats.

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

For model-driven apps, in the legacy web client, when adding a control on a form bound to an autonumber column, the control is disabled automatically and behaves as read-only in the form where end-users cannot edit the control. In Unified Interface, controls bound to an autonumber column need to explicitly be set as disabled. If you do not set the initial column value on the form, the value is set only after you save the table. Autonumbering can be applied to column values in views, grids and so on.

Examples

The following examples show how to create a new autonumber column named new_SerialNumber for a custom table named new_Widget which will have a value that looks like this: WID-00001-AB7LSFG-20170913070240 using the Web API and the Dataverse SDK for .NET.

  • Web API
  • SDK for .NET

You can create and update table definitions using the Web API. More information: Create and update table definitions using the Web API.

Request

POST [Organization URI]/api/data/v9.0/EntityDefinitions(LogicalName='new_widget')/Attributes HTTP/1.1Accept: application/jsonContent-Type: application/json; charset=utf-8OData-MaxVersion: 4.0OData-Version: 4.0{ "AttributeType": "String", "AttributeTypeName": { "Value": "StringType" }, "Description": { "@odata.type": "Microsoft.Dynamics.CRM.Label", "LocalizedLabels": [ { "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel", "Label": "Serial Number of the widget.", "LanguageCode": 1033 } ] }, "DisplayName": { "@odata.type": "Microsoft.Dynamics.CRM.Label", "LocalizedLabels": [ { "@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel", "Label": "Serial Number", "LanguageCode": 1033 } ] }, "RequiredLevel": { "Value": "None", "CanBeChanged": true, "ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings" }, "SchemaName": "new_SerialNumber", "AutoNumberFormat": "WID-{SEQNUM:5}-{RANDSTRING:6}-{DATETIMEUTC:yyyyMMddhhmmss}", "@odata.type": "Microsoft.Dynamics.CRM.StringAttributeMetadata", "FormatName": { "Value": "Text" }, "MaxLength": 100}

Response

HTTP/1.1 204 No ContentOData-Version: 4.0OData-EntityId: [Organization URI]/api/data/v9.0/EntityDefinitions(402fa40f-287c-e511-80d2-00155d2a68d2)/Attributes(f01bef16-287c-e511-80d2-00155d2a68d2)

Note

Autonumber values are preselected by the database when the record is started. If a record is started but cancelled, the number it was assigned is not used. If, during this time, another record is completed with the next sequential number, gaps will be present in the autonumbering of records.

AutoNumberFormat options

These examples show how you can configure the AutoNumberFormat Property to get different results:

AutoNumberFormat valueExample value
CAR-{SEQNUM:3}-{RANDSTRING:6}CAR-123-AB7LSF
CNR-{RANDSTRING:4}-{SEQNUM:4}CNR-WXYZ-1000
{SEQNUM:6}-#-{RANDSTRING:3}123456-#-R3V
KA-{SEQNUM:4}KA-0001
{SEQNUM:10}1234567890
QUO-{SEQNUM:3}#{RANDSTRING:3}#{RANDSTRING:5}QUO-123#ABC#PQ2ST
QUO-{SEQNUM:7}{RANDSTRING:5}QUO-0001000P9G3R
CAS-{SEQNUM:6}-{RANDSTRING:6}-{DATETIMEUTC:yyyyMMddhhmmss}CAS-002000-S1P0H0-20170913091544
CAS-{SEQNUM:6}-{DATETIMEUTC:yyyyMMddhh}-{RANDSTRING:6}CAS-002002-2017091309-HTZOUR
CAS-{SEQNUM:6}-{DATETIMEUTC:yyyyMM}-{RANDSTRING:6}-{DATETIMEUTC:hhmmss}CAS-002000-201709-Z8M2Z6-110901

The random string placeholders are optional.You can include more than one random string placeholder. Use any of the format value for datetime placeholders from Standard date and time format strings.

String length

The table shows the string length value for the random and sequential placeholders.

PlaceholderString LengthOutput Scenario
{RANDSTRING:MIN_LENGTH}The value of MIN_LENGTH is between 1 and 6.When you save the row, the autonumber column generates the random string with the defined length if the value is between 1 and 6. If you use the MIN_LENGTH value as 7 or beyond 7, you get to see an Invalid Argument error.
{SEQNUM:MIN_LENGTH}The minimum value of the MIN_LENGTH is 1. The number continues to increment beyond the minimum length.When you save the row, the autonumber column works fine and continue to work fine for larger values of MIN_LENGTH.

For sequential value placeholders, the MIN_LENGTH is a minimum length. If you set the value to be 2, the initial value will be 01, and the 100th row value will be 100. The number will continue to increment beyond the minimum length. The value in setting the length for sequential values is to establish a consistent length for the autogenerated value by adding additional 0s to the initial value. It will not limit the absolute value. Random value placeholders will always be the same length.

Because the sequential values can get larger than the minimum length allotted for them, you should not adjust the StringAttributeMetadata.MaxLength Property to match the length of your formatted value. There is little value in doing this and it could cause an error in the future if the value exceeds the MaxLength value. Make sure you leave enough room for a realistic range of sequential values.

Note

There is no validation of the placeholder values when you create the column. The error appears only when you try to save a table that uses an incorrectly configured AutoNumberFormat value.For example, if you specify the length of the random string more than 6, the first person creating a new table gets an Invalid Argument error when they first try to save the table containing the new autonumber column.

Update autonumber columns

If you create an autonumber column with an incorrect configuration or you want to modify an existing autonumber column, you can update the column the AutoNumberFormat value.

The following code snippet explains you to retrieve, modify, and update the autonumber column using the SDK for .NET:

To modify an existing autonumber column, you must retrieve the column using the RetrieveAttributeRequest Class.

// Create the retrieve requestvar attributeRequest = new RetrieveAttributeRequest { EntityLogicalName = entityName.ToLower(), LogicalName = "new_serialnumber", RetrieveAsIfPublished = true };// Retrieve attribute responsevar attributeResponse = (RetrieveAttributeResponse)_serviceProxy.Execute(attributeRequest);

After retrieving the autonumber column, you need to modify and update the column.

//Modify the retrieved autonumber columnAttributeMetadata retrievedAttributeMetadata = attributeResponse.AttributeMetadata;//Modify the existing column by writing the format as per your requirementretrievedAttributeMetadata.AutoNumberFormat = "CAR-{RANDSTRING:5}{SEQNUM:6}"; // Update the autonumber column var updateRequest = new UpdateAttributeRequest { Attribute = retrievedAttributeMetadata, EntityName = "newWidget", };// Execute the request_serviceProxy.Execute(updateRequest);

Set a seed value

By default, all autonumber sequential values start with 1000 and use 0 as the prefix depending on the length. In this way, the length of the value is always same. If you want to change the initial value, you need to change the initial seed value using the API below to set the next number that are used for the sequential segment.

For example, when the length of the sequential number is 5, you may want to start with an initial value of 10000 instead of the default value of 00001.If you want to choose a different starting value after creating the autonumbering column, use the SetAutoNumberSeed message. Use the SetAutoNumberSeedRequest Class when using the SDK assemblies and SetAutoNumberSeed Action when using the Web API.

The AutoNumberSeed message has the following parameters:

NameTypeDescription
EntityNamestringThe logical name of the table that contains the column you want to set the seed on.
AttributeNamestringThe logical name of the column you want to set the seed on.
ValueintNext autonumber value for the column.

Note

Setting the seed only changes the current number value for the specified column in the current environment. It does not imply a common start value for the column. The seed value is not included in a solution when installed in a different environments. To set the starting number after a solution import, use SetAutoNumberSeed message in the target environment.

SetAutoNumberSeed Examples

The following samples set the seed to 10000 for an autonumber column named new_SerialNumber for a custom table named new_Widget.

  • Web API
  • SDK for .NET

Using the Web API SetAutoNumberSeed Action.

Request

POST [Organization URI]/api/data/v9.0/SetAutoNumberSeed HTTP/1.1Accept: application/jsonContent-Type: application/json; charset=utf-8OData-MaxVersion: 4.0OData-Version: 4.0{ "EntityName": "new_Widget", "AttributeName": "new_Serialnumber", "Value": 10000} 

Response

HTTP/1.1 204 No ContentOData-Version: 4.0

More information: Use Web API actions > Unbound actions

Auto Number Manager

Auto Number Manager for XrmToolBox is a community driven tool for Dataverse that provides a UI to set, update and remove autonumber format on new or existing columns.

Please see the Developer tools topic for community developed tools and anm.xrmtoolbox.com for more information about Auto Number Manager.

Note

The community tools are not a product of Dataverse and does not extend support to the community tools.If you have questions pertaining to the tool, please contact the publisher. More Information: XrmToolBox.

See Also

Work with table definitions using code
Customize table definitions

Create autonumber columns (Microsoft Dataverse) - Power Apps (2024)

FAQs

Create autonumber columns (Microsoft Dataverse) - Power Apps? ›

Create an autonumber column
  1. Sign in to the Power Apps portal.
  2. On the left pane expand Data and select Tables.
  3. Select the table that you would like to add an autonumber column to and then select Columns.
  4. On the toolbar, select Add column.
  5. On the right pane, enter a Display name and select Autonumber for the Data type.
Jun 22, 2022

How do you add columns in Dataverse? ›

You should use the Power Apps portal to create and edit columns for Dataverse unless you need to address any of the following requirements:
  1. Create a Customer Lookup column. ...
  2. Create a column in a solution other than the Common Data Service Default Solution. ...
  3. Define status reason transitions. ...
  4. Edit multiple columns at once.
Jun 3, 2022

How do you change the datatype of a column in Dataverse? ›

Edit a column

While viewing columns, select the column you want to edit. You can modify the Display Name but you cannot change the Name and Data type if you have saved changes to the table to add the column.

What is the use of AutoNumber type field? ›

AutoNumber is a type of data used in Microsoft Access tables to generate an automatically incremented numeric counter. It may be used to create an identity column which uniquely identifies each record of a table. Only one AutoNumber is allowed in each table. The data type was called Counter in Access 2.0.

What is Microsoft Dataverse in power apps? ›

Dataverse allows data to be integrated from multiple sources into a single store, which can then be used in Power Apps, Power Automate, Power BI, and Power Virtual Agents along with data that's already available from the Dynamics 365 applications.

How do you create a data table in Dataverse? ›

Create Tables in Dataverse – Part 1 - YouTube

How do I create a calculated field in Powerapps? ›

Create a calculated column
  1. Sign into Power Apps.
  2. Expand Data > Tables.
  3. Open the table you want, select the Columns area, and then select Add Column.
  4. Provide the required information for the column, including the Display name, Name, and Data type.
Jun 22, 2022

What is primary name column in Dataverse table? ›

Primary name

The PrimaryNameAttribute property value is the logical name of the column that stores the string value that identifies the table record. This is the value that will be displayed in a link to open the record in a UI. Example: The Contact table uses the fullname column as the primary name column.

Can you change existing field names and add new fields of Dataverse? ›

The only way was to create a new field, transfer all data from the old field to the new one and then delete the old field.

How many apps can use the same Dataverse table? ›

Yes, you can use the same table on as many apps you need. Each app need a connection to this table. To assure a sync between local data on each app and datasource there is a function Refresh(database) that can be called based on a timer control.

How do I add AutoNumber data type? ›

In the Navigation Pane, right-click the table to which you want to add the primary key, and click Design View. Tip: If you don't see the Navigation Pane, press F11 to display it. Locate the first available empty row in the table design grid. In the Data Type field, click the drop-down arrow and click AutoNumber.

Which enables you to create auto numbering fields? ›

Once you have create your auto number field, you can add the AutoNumber field in a form.
  • Select the Form where you want to add the auto number fiel, in the entity where you create it.
  • Once there, go to the Field explorer and select your auto number field.
  • You can then drag your auto number field on the form.
Sep 28, 2021

What is difference between number and AutoNumber data type? ›

Number type can store any integer/float value, depending on decimal precision specified. Whereas Auto Number will have values calculated by system. (Auto Incremented Values).

What is the difference between Dataverse and database? ›

1.2.

Microsoft Dataverse is a new type of relational database that stores its data within a set of tables or entities. A table is a set of rows (registers) and columns (fields). As usual, every column is designed to store a specific type of data.

What is difference between Dataverse and CDS? ›

Common Data Service (CDS) — the data storage system that intensifies Dynamics 365 and Power Platform — has changed its name to Dataverse, part of a bigger rebrand at Microsoft. Dataverse does the same thing as CDS — but with a different name.

Is Microsoft Dataverse free? ›

Microsoft Dataverse for Teams is free. You don't have to buy an additional subscription to use it. Subscriptions that allows you to use Microsoft Dataverse for Teams for free: Office 365 E1, E3, E5, F3.

How do I add a field in Powerapps? ›

Add columns to a form using drag and drop
  1. Open the form designer to create or edit a form. ...
  2. On the command bar, select Add column, or in the left pane, select Columns. ...
  3. In the Columns pane, search, filter, or scroll to find the column you want to add. ...
  4. In the Columns pane, select a column and drag it onto the form preview.
Jul 13, 2022

How is data stored in Dataverse? ›

Dataverse securely stores and manages data used by business applications. The data is stored within a set of tables where the table is a set of rows and columns. And Each column in the table is designed to store any certain type of data. Let's say, for example, name, salary, age, DOB, etc.

How do you create a Dataverse environment? ›

How do I provision a Dataverse environment? | 365.Training

How do you connect data to Dataverse? ›

Connect to Dataverse from Power BI Desktop

Select Get data from the Home tab. In the Get Data dialog box, select Power Platform > Dataverse, and then select Connect. If this attempt is the first time you're connecting to this site, select Sign in and input your credentials. Then select Connect.

Top Articles
Latest Posts
Article information

Author: Wyatt Volkman LLD

Last Updated:

Views: 5955

Rating: 4.6 / 5 (66 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Wyatt Volkman LLD

Birthday: 1992-02-16

Address: Suite 851 78549 Lubowitz Well, Wardside, TX 98080-8615

Phone: +67618977178100

Job: Manufacturing Director

Hobby: Running, Mountaineering, Inline skating, Writing, Baton twirling, Computer programming, Stone skipping

Introduction: My name is Wyatt Volkman LLD, I am a handsome, rich, comfortable, lively, zealous, graceful, gifted person who loves writing and wants to share my knowledge and understanding with you.