Atomically updating UD01 counters

We have a few BPMs that assign customer IDs, ship to numbers, one-off part numbers, etc. by getting the current value from the appropriate row of UD01, incrementing it, writing it back, and calling Db.Validate(). One of these was written in 2010 by someone with an epicor.com email address, and I think the others were copied from that. Incrementing a counter this way is not atomic, and we’ve run into situations in production where two order lines were assigned the same one-off part number. Is there a preferred way to make this atomic?

Here’s my own crazy idea. Apparently there is no general way to perform an atomic increment through an EF DbContext. But if all BPMs execute in the same AppDomain, we could make a section atomic by synchronizing on a static variable. If nothing else, we could sync on a Type. Can anyone think of a reason this won’t work?

Search this site tehre are quite a few threads on this. But Epicor provides a library to do exactly this. It has been discussed here extensively.

My search-fu is failing, maybe because I know the word “atomic” and don’t know what else to call it.

Auto increment,
Auto sequence
here’s a few of the posts

1 Like

That third link is a treasure trove.

1 Like