Set a prefix in the entity ID field

Hi guys,
can we set a prefix in the entity ID field with auto-increment? and how to achieve that?

It’s a combination of things. Since you’re not using a standard sequence, the way that I can remember (others might correct me) is to:

  • Decide on the sequence custom name that you want defined in the moqui.entity.SequenceValueItem entity. For example CustomOrderId or whatever
  • Then instead of just using the auto services / auto entity API, you should generate the sequence manually using String sequencedIdPrimary(String seqName, Long staggerMax, Long bankSize) from EntityFacade.java so for example you would use a call like the following:
ec.entity
    .makeValue('mantle.order.Order')
    .set('orderId', ec.entity.sequencedIdPrimary('CustomOrderId', 1, 1))
    .store()
2 Likes

I should make the correction also that you insert the prefix by hand so:

def generatedSeq = ec.entity.sequencedIdPrimary('CustomOrderId', 1, 1))
ec.entity
    .makeValue('mantle.order.Order')
    .set('orderId', "PREFIX_${generatedSeq}")
    .store()
2 Likes

Thanks for this @taher

1 Like