Commit Object instantly after changing the value in Java action

0
Hi All, I am working on a requirement where we have to create unique reference number (customized - Example - XXXX01234). Problem is, when we use the latest used number in DB, sometimes we can get the same number for different transactions as the commit is not getting completed until all the microflows complete running. I have decided to do these things in Java action and it doesn't help me either. Below is my Java code. Can anyone help me if we can do commit instantly in DB using Java action. Appreciate your help. Java Code: Sequence ProductSequenceObj = this.ProductParameter1.getProduct_Sequence().get(0);         switch (ParameterParameter1)          {         case Quote:                         newSequenceNo = ProductSequenceObj.getLatestAssignedNumberQuotes()+1;             ProductSequenceObj.setLatestAssignedNumberQuotes(newSequenceNo);                         ProductSequenceObj.commit();             break;                                  default:             newSequenceNo = ProductSequenceObj.getLatestAssignedNumberPolicies()+1;             ProductSequenceObj.setLatestAssignedNumberPolicies(newSequenceNo);             Core.commitWithoutEvents(getContext(), seQuenceEntity);             ProductSequenceObj.commit();             break;         }         return (long) newSequenceNo; Thanks, Nags
asked
2 answers
1

You need a java Mutex for that, there is enough information on internet for that subject available, for example this.

After that the commit is done (within mutex code) use session.endTransaction (see community) to save the number

answered
0

Hi Nags,

If you're specifically looking to have a sequence for quotenumbers, probably a good idea to create a QuoteNumberSequence entity just for this, make it have an autonumber field, and use this autonumber field as part of determining the quote number. Everytime you need a new quote number, you just create a new QuoteNumberSequence record and read it's autonumber field.

The platform will guarantee these autonumbers to be unique and sequential, even when running on multiple nodes.

answered