Special nodes should have own workflows

  Written by The Jahia Team
   Estimated reading time:
Is it possible to have nodes which have an own workflow without inherit it from parent. Without any manual change in workflow tab.


Yes it is possible you can define a simple rule, when this nodetype is created an own worklfow is set.
The rule could look like:

rule "Add default workflow to node"
salience 50
    A new node is created
    - the node has the type mix:yourMixintoBreakWF
    Add the type jmix:workflowRulesable
    Log "Add workflow to " + node.getPath() > WorkflowRuleHelper.addWorkflow(node);

Inside the WorkflowRuleHelper.addWorkflow(node) you can set the default workflow which is expected in my case it looks like:

public static void addWorkflow(NodeFact nodeFact) {

    try {
        logger.info("set default workspace on node " + nodeFact.getPath());
        JCRNodeWrapper node = nodeFact.getSession().getNode(nodeFact.getPath());
        if (node.hasNode("j:workflowRules")) {
            JCRNodeWrapper wfRules = node.getNode("j:workflowRules");
            if (!node.hasNode("jBPM_1-step-publication-remotepublish")) {
                JCRNodeWrapper rule = wfRules.addNode("jBPM_1-step-publication-remotepublish", "jnt:workflowRule");
                rule.setProperty("j:workflow", "jBPM:1-step-publication-remotepublish");
    } catch (RepositoryException ex) {
        logger.error("Error when set default workflow on node ", ex);