Auto Generated Unique number

0
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?     
asked
3 answers
5

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.

answered
0

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)

answered
0

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 :

$lastProductNumber=’SL1_UP_31032021_01’

 

your String function will be like :

 

SubString($$lastProductNumber,FindLast($lastProductNumber,’_’)

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!!

 

answered