Serial Number Generation

Serial Number Generation

Hi ,

I am new to outsystems platform. I have a requirement in my application to generate 10 digit serial Number 
of this format ( 'A000000001 , A000000002 , A000000003..........). Please guide me how this can be done in Outsystems platform. Thanks in Advance.

Rakesh -

Do an aggregate query on the entity with no filters to get the count of rows. Then take that result and add the letters at the beginning with with a variable assignment to get the new serial number. You will probably want to add an index to the entity you are storing the serial number in, with "Unique" set to true, to make sure that they are always unique.


Hi Justin ,

Thanks for the information . But the concern is that upon my serial no reaching to A999999999 , the next number 
should be B000000001.....and so on. Please suggest how can increment letter 'A' . Do we have any function
that increments letters.Thanks in Advance.
I don't know if it is possible to increment the letter "A". But an alternative is to implement an if/else statement function for when you reach "A999999999". 
If you are concerned about this wraparound, that would indicate that you are expecting a large number of records in that entity.  If that is true, Justin's solution may not perform as well as you would like.  In addition, if you delete any records it won't work correctly.

What I do in this case is the following.  

1) Create an Entity with three fields - Id (integer, not autonumber), AlphaCode (Text, 1 character), NumberCode (decimal, 9 digits).

2) Create an action that will check the count and if less than one, create a record with - Id = 1, AlphaCode = 'A', NumberCode = 1 (this is similar to Excel bootstrap code that Outsystems creates)

3) Create a timer set to When Published that calls the action you created in step 2

4) Create a function action that returns a text field of 10 characters and is called whenever the code needs to be incremented - read the record where Id = 1, if NumberCode = 999999999 increment the AlphaCode ('A' becomes 'B', etc.) and set NumberCode to 1 otherwise increment NumberCode - string together the AlphaCode and NumberCode values and return that string 

It's a pain that you have to do all that but it's the best way IMHO.

Hope this helps,

P.S.  Just FYI, this is not an Outsystems issue,  I've solved this problem the same way across many systems, languages and platforms going back to COBOL on the oldest mainframes.