Hi @rmcmun
There are a couple of ways to do this. To create a unique number you could set a TextInput box on a form with the value in the card assigned to the item ID.
Coalesce(Parent.Default,First(Sort(datasource, someID, Descending)).someID+1)
This would allow for a New item (ie. Parent.Default would be null) to be assigned the next ID number but when the form is in Edit mode the ID would be retained. I either hide this card or make it Disabled so that a user can't change the value.
To prevent a duplicate in the Primary Name column from being assigned, I put this code in the OnSelect property of the button that saves the record.
If(
IsBlank(
Lookup(datasource,Lower(Trim(PrimaryName))=Lower((Trim(TextInput1.Text))
)
),SubmitForm(
Form1
),
Notify(
"There is already an item with that name in the database. Please change the
item name.", Error
)
)
Lower(Trim(... is used to prevent users from adding the same name but with a space or changing the case.
In the OnSuccess property of the form Notify("Your item has been successfully added", Success)
One of my general database design principles is that the unique Primary key of a table should not have any meaning and is not revealed to the user.