Is is possible to do @Unique() inside Java in XPages?

xpages

Solution

Yes you can. When you get a handle to Session call evaluate. You can evaluate any formula expressions with this method.

String ID = (String)session.evaluate("@Unique").elementAt(0);

Problem

When I want a unique key for documents I'm partial to using @Unique(). I like that it's based on username and time. Is there a way to get that from inside a Java bean? If not, what's the best way to get a unique number in Java that would not repeat? Thanks

Original source