Custom ID number

Custom ID number

  

Hello,


We're asked to generate an identifier number for one of  our entity table in this format YYMMXXXX where YY = 2-digit year, MM = 2-digit month and XXXX = sequential 4-digit. I was planning to use the entity identifier number generate by the system and modulo 9999 then pad 0 to the result and add YYMM to the front. However, at the time the record is saved, is there a way to find the current Entity Identifier? Or what's a better way to do this?


Thanks

Solution

Hi Tim,

If the entity identifier is generated automatically (Auto-Number), then you will have to create the record first (with your identifier number empty or with some dummy value). After creating the record use the output of the CreateEntity action to compute your entity and use UpdateEntity to update the record.

Don't forget that before updating the record you will have to do the assign of your identifier and also of the entity identifier to the record that you are updating (typically it is the same variable that you used to do the create).

Cheers,

José

Solution

Tim Le wrote:

Hello,


We're asked to generate an identifier number for one of  our entity table in this format YYMMXXXX where YY = 2-digit year, MM = 2-digit month and XXXX = sequential 4-digit. I was planning to use the entity identifier number generate by the system and modulo 9999 then pad 0 to the result and add YYMM to the front. However, at the time the record is saved, is there a way to find the current Entity Identifier? Or what's a better way to do this?


Thanks

hi Tim,

Other way: you can create a procedure/function in database that return a sequence (database sequence) and then use that to create the ID.

regards,

bb


Tim,

You can also create an action to generate this number, to get the last one you may create an entity which stores the last generated, within your action you get the last one and logic to create the next one.


Shashank...

Hi Shashank,

Yes, you can also do that. But in that case, you must be careful on how to generate it, because multiple transactions can be running at the same time and generating the same Id.

In that case, you should have the last generated Id in that new entity, use the Get<Entity>ForUpdate to get the last one (and also lock that record), generate the next one (increment), and update the record.

This way you will not get repeated Ids.

Cheers,

José

Hi Jose,

You are absolutely right, i should have mention it, thanks for correcting.


Shashank...

Hi folks, I just stumbled upon this thread while looking for a similar question. 

In my case, I'm implementing a seed generator, based on an entity without an identifier that is using a unique index over 4 attributes A, B, C, D (of multiple data types). I intend to lock access to this table during a brief second, in order to make sure that if my logic flow ends fine, I can then commit the newly generated 4-attribute sequence. Otherwise (in case of an error, for example) that 4-attribute generated sequence will not be saved. This will resolve the multiple transactions that might be occurring during that call. How does one implement such an exclusive lock for this type of entity? GetForUpdate<Entity> action will not work since I no longer have a single attribute Identifier...