In this post, we will take a look at how to create a field in Power Apps Dynamics 365 that auto-generates a value. This is useful if you would like records to have unique values that are automatically generated. You can add these fields to out of the box entities and also custom entities.
Let’s create on in the Account entity. Go to https://make.powerapps.com and select Account:
Then add field:
Change the type to Autonumber:
In selecting autonumber, this displays a new section with fields to configure how our values will look in our new field.
We see Autonumber type is the first thing to configure:
Here we can choose from:
- String prefixed number
- Date prefixed number
- Custom
If we select string prefixed number, we can enter a string, e.g. below I am entering ACCT. This is the prefix of the new value. I am also selecting 4 digits for the number that will be added to the prefix, starting at 1000 (the seed value). We see in the preview this generates ACCT-1000, ACCT-1001 etc. So the first record will have the value ACCT-1000, the second ACCT-1001 etc:
If we change this to 10 digits, and a seed of 50,000, we get a different value generated:
If we use date prefixed number, if adds a date in the format YYYY-MM-DD. We can then add the digits and seed:
With Custom types, we can define the format ourselves. We see how the format is made up here:
Let’s try the format below. We see the date is the prefix, then a sequence number of 4 digits:
{DATETIMEUTC:yyyy-dd-MM}-{SEQNUM:4}
We can add sequence numbers, dates and random strings to our custom format:
A simple sequence number of 7 looks like:
{SEQNUM:7}
Pressing Add datetime to format appends the date:
If we select Random string, it generates a random string as expected:
Let’s create a custom autonumber type using all of the above:
AUTO-{SEQNUM:4}-{DATETIMEUTC:yyyy-dd-MM}{RANDSTRING:4}
Save the field and let’s add it to the form:
Create a new account record. On opening the record, the value is not generated:
On saving the record, the field value is now generated in our format:
The field is editable but you could make this read-only:
Note clearing out the field is does not regenerate the value:
I AM SPENDING MORE TIME THESE DAYS CREATING YOUTUBE VIDEOS TO HELP PEOPLE LEARN THE MICROSOFT POWER PLATFORM.
IF YOU WOULD LIKE TO SEE HOW I BUILD APPS, OR FIND SOMETHING USEFUL READING MY BLOG, I WOULD REALLY APPRECIATE YOU SUBSCRIBING TO MY YOUTUBE CHANNEL.
THANK YOU, AND LET'S KEEP LEARNING TOGETHER.
CARL
Can we add autonumber on opportunity entity. I am not able to see opportunity entity in power app Entities
Is it possible to update or regenerate a new value after the auto number is generated