0

I have a Java agents which generates documents. I also give these document a custom unique follow number, starting at 1 and increment +1 every time. I have a view where I get the last number, I take this number and increment it with one. So whenever the agent runs it increments this number, this happens by a piece of code which is at the bottom of this question. Sometimes this agents is called simultaneously and this results in getting the same number. So I have documents for example which has the numer 1001, 4 times and not 1001, 1002,1003,1004.

I tried to look if an agent can run one at a time but this is only the case for scheduled agents.

The code which I run to generate the unique number is:

String ReturnValue = "";

                View nvwVolgnr =  iOrderDB.getView("Volgnummer");
                lotus.domino.Document docVolgnr = nvwVolgnr.getDocumentByKey("Order");
                if ( docVolgnr!=null){
                    String strVolgnr = docVolgnr.getItemValue("Volgnummer").toString();

                     //System.out.println("strVolgnr " + strVolgnr);

                    //Object intVolgnr = docVolgnr.getItemValue("Volgnummer");

                    strVolgnr = strVolgnr.replace("[", "");
                    strVolgnr = strVolgnr.replace("]", "");

                    double intVolgnr = Double.parseDouble(strVolgnr);

                    strVolgnr = strVolgnr.replace(".0", "");

                    //System.out.println("strVolgnr " + strVolgnr);

                    strVolgnr = "000000" + strVolgnr;
                    //System.out.println("strVolgnr " + strVolgnr);

                    strVolgnr = strVolgnr.substring(strVolgnr.length() - 6);
                    ReturnValue = strVolgnr;

                    intVolgnr = intVolgnr + 1;
                    Double dblVolgnr = new Double(intVolgnr);

                    //System.out.println("strVolgnr " + strVolgnr);

                    //Object objVolgnr =  intVolgnr;

                    docVolgnr.replaceItemValue("Volgnummer", dblVolgnr);
                     if (docVolgnr.save())
                        {

                        }

Is there any way to get unique numbers (with the increment) even when this agent runs simultaneous

Nuri Ensing
  • 1,899
  • 1
  • 19
  • 42
  • You should probably read Andre Guirard's post about sequential numbering in Notes and Domino. https://www-10.lotus.com/ldd/ddwiki.nsf/dx/sequential-numbering.htm – Richard Schwartz May 15 '19 at 01:36

1 Answers1

0

The easiest way would probably be to set up a single point of truth: This could be an extra local agent, a file, a database or an API. You can get the next number from any of these.

This means that you setup one of these to give your agents the next number. Since this happens on a single location, you will no longer have any duplicates.

If incrementing the numbers is not needed, but you just need to have a unique number for each, you can look at UUID's. But I believe that is not the case.

PimJ
  • 38
  • 7
  • I have a view where I get the last number, I take this number and increment it with one. – Nuri Ensing May 14 '19 at 12:37
  • In that case, this might be what you are looking for: https://stackoverflow.com/questions/8532296/how-to-create-an-auto-incrementing-field-in-lotus-domino – PimJ May 14 '19 at 13:05