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