Auto-Increment or Sequence Generators in BloomReach

Hello,

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.

Thank you very much,
Nick

You could make use of:


to achieve this. You can create a node somewhere where you hold your global counter e.g. by creating a mixin:

[sequence:identifier] mixin

  • sequence:number (long) = ‘0’ autocreated

Combining this with derived data function (or custom workflow step) would probably get you there.

I would use scxml for this.

create a new action and task workflow to and using the documentation marijan provided above for the lock

    **<hippo:uid/>**
    <if cond="!editor">

in scxml action and task:

  /uid:
    jcr:primaryType: hipposcxml:action
    hipposcxml:classname: com.bloomreach.cms.workflow.UIDAction
    hipposcxml:namespace: http://www.onehippo.org/cms7/repository/scxml

code in task:

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);
        }
    }

+1
Derived data function is always easier than anything else if applicable.