UniqueNumbersService in cuba 7.2.6

Hi,

I’m trying to get the number sequence tho work in cuba with no succes. I checked the forum and google but all the topics and solutions are to old. And the manual is’nt in my opinion very specific about this topic. My code is:

@Inject
private UniqueNumbersService unService;

@Subscribe
protected void initNewItem(GrondRegistratie item) {
    item.setAanvraagNummer(unService.getNextNumber("AanvraagNummer_597000000000"));
}

}

Can anyone please point me out in the right direction.

Regards,

LS

Mmm. I’ve used the UniqueNumberService in Kotlin and it seems to work fine, so I’m not sure why it doesn’t work in your case.

You haven’t said exactly what your’e seeing though. Looking at your code, it’s possible that the number is being generated, but the item property is not being set. I would start by assigning unService.getNextNumber to a variable and run it through the debugger to make sure that’s working.

Hi Ray,

I’m not seeing anything that’s the problem. Is it possible to help me with the exact code? In the manual i haven’t seen a step by step option.

Regards,

LS.

No problem.

    @Inject
    private lateinit var uniqueNumbersService: UniqueNumbersService

...
...

    val nextReferenceNumber = uniqueNumbersService.getNextNumber("MANUSCRIPT_REFERENCE")

That’s in Kotlin, but it should be fine in Java as it’s exactly the same code. I’ve tried it with the seed value you used and it works.

The only difference I can see is that you have called it directly inside a screen handler. Mine is called as part of a service. Could you try transferring the code into a service and seeing if that makes a difference?

The manual also mentions a different API, which you could also try, though I’m not sure that does anything different.

https://doc.cuba-platform.com/manual-latest/uniqueNumbers.html