Start page / Tutorials / Workflows / Workflow “RecursiveLock”

Example: “RecursiveLock” workflow

This workflow for locking subtrees recursively consists of the workflow itself and the corresponding “lockrecursive” script.

Within the script, recursive write protection is applied to the element where the workflow was started. In order for this to work, the write protection set automatically by the workflow must first be canceled. This involves removing the write protection in the “WriteLockOff” state.

The “Write protection” checkbox is unchecked, which means the write protection set by the workflow is canceled when the “Recursive Lock Test” transition is switched. The subsequent action, “DoRecursiveLock”, runs automatically and is linked to the “lockrecursive” script.

Recursive write protection can now be set on the element by using the script:

// set recursive lock
se = context.getElement();
se.setLock(true);
text = "Subtree locked!";
    requestOperation = context.requireSpecialist(OperationAgent.TYPE).getOperation(RequestOperation.TYPE);
    requestOperation.setKind(RequestOperation.Kind.INFO);
    requestOperation.addOk();
    requestOperation.perform(text);

The elements are locked recursively; the editor is shown a dialog with the message “Subtree locked”.

When the message is confirmed, the script continues running and the recursive write protection applied to the subtree is removed again:

// reset recursive lock
se.setLock(false);

In the next step, simple write protection has to be restored on the element:

// non recursive lock, normal state during workflow
se.setLock(true, false);
context.doTransition("->WriteLockOn");

This is necessary so that the subsequent transition can be switched within the workflow.

Finally, standard write protection set by the workflow has to be restored. This is done by reactivating the “Write protection” checkbox in the “WriteLockOn” state:

Script “lockrecursive”:

//!Beanshell
import de.espirit.firstspirit.common.gui.*;
import de.espirit.firstspirit.ui.operations.RequestOperation;
import de.espirit.firstspirit.agency.OperationAgent;
 
// set recursive lock
se = context.getElement();
se.setLock(true);
text = "Subtree locked!";
          requestOperation = context.requireSpecialist(OperationAgent.TYPE).getOperation(RequestOperation.TYPE);
          requestOperation.setKind(RequestOperation.Kind.INFO);
          requestOperation.addOk();
          requestOperation.perform(text);
 
// reset recursive lock
se.setLock(false);
 
// non recursive lock, normal state during workflow
se.setLock(true, false);
context.doTransition("->WriteLockOn");

© 2005 - 2024 Crownpeak Technology GmbH | All rights reserved. | FirstSpirit 2024.5 | Data privacy