I’m wondering if anyone might know of a way to introduce a number sequencing (auto-incrementing) generator in a BloomReach document.
I need a number key that’s human-readable, so that it can be conveniently provided to a CSR agent, for example. (As opposed to a UUID, which is unwieldy.)
More context:
One of our web pages on our site consists of a web form that results in saving a document in the CMS, when the user submits that form. This is working fine so far, but we also require a means of incorporating an auto-incrementing integer sequence into that document. (So that the user-friendly field value increases for each document, eg., 100001, 100002, 100003, …)
As always, any help, tips, or references would be very much appreciated.
if (!draft.hasProperty(property)) {
try (LockResource ignore = lockManager.lock(key)) {
// session.refresh(true|false) is JCR nodes are involved
// Do work
Node uidGeneration = getWorkflowContext().getInternalWorkflowSession().getNode(key);
long id = uidGeneration.getProperty(“id”).getLong();
long docUid = id++;
draft.setProperty(property, String.format("%08d", docUid));
draft.getSession().save();
uidGeneration.setProperty("id", id);
uidGeneration.getSession().save();
} catch (AlreadyLockedException e) {
log.info("'{}' is already locked", key, e);
} catch (LockException e) {
log.error("Exception while trying to obtain lock", e);
}
}