Auto Generated Unique number

Hi, while adding a product , For every product in my app I want to give auto generated serial number in the format – SL1_UP_31032021_01 this number should be incremented automatically by one every time I add a new product. Can anyone help me on this?     
3 answers

You could store the last generated number in an entity. When you build the next serial number retrieve this, increment it, store it, and then use it in the serial number.

You will probably want to protect this entity by providing this functionality via a dedicated microflow that has concurrency disallowed.


You could create an entity with 1 Attribute: Autonumber.

Every time you need to generate a new unique code you can create 1 of that object( no need to commit the object).

The value of that Autonumber attribute can then be used to create your unique code: 

MyUniqueValue = ‘SL1_UP_31032021_’ + toString($TheAutonumberAttribute)


HI shaan ahmed,

 You already have many answers above, but still i will also help you out here,
Retrieve the latest object that is added from data base( you can enable Created date ) . 

Your String has ‘_’ as key . So you can FindLast()  and substring string functions from mendix. 

FindLast()- returns the index position of the last occurence of key word “ _ “. 

Substring ($string,IndexNumber)- Returns the Digits after the “ _ ”

Example :



your String function will be like :



this will yield you – 01 

With the help of FormatIntger convert the string to a number and add +1 


Then reconstruct the string as needed.


Hope it Helps!!