Workflow Condition Scripts#

You can assign a workflow condition script to state transitions in workflows. This script is executed

  • when loading an item for editing

  • when saving with the state transition to which the script is assigned

In the first case, the condition script influences the states available in the state selection list of the item during editing. In the second case, the condition script can block the desired state transition.

A condition script can perform any checks and returns either “true” or “false”.

Examples#

The following script is placed in the workflow between the transition from the initial state (black circle) to the first regular state and prevents automatically generated emails such as out-of-office messages from creating an item in the system.

import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import com.aurel.track.admin.customize.scripting.BINDING_PARAMS;
import com.aurel.track.admin.customize.scripting.GroovyScriptExecuter;
import com.aurel.track.util.emailHandling.EmailCleanUtils;

public class EmailGuardScript {
    private static String PARAMETER_SCRIPT_NAME = "EmailGuardParams";
    private static String PARAMETER_SCRIPT_METHOD = "getRejectPatterns";

    public Map<String, Object> handleEvent(Map<String, Object> inputBinding) {
        String subject = (String)inputBinding.get(BINDING_PARAMS.EMAIL_SUBJECT);
        if (subject != null) {
            List<Pattern> rejectPatterns =
                    (List<Pattern>)GroovyScriptExecuter
                    .getParameterInstanceGroovyHandler(
                    PARAMETER_SCRIPT_NAME, PARAMETER_SCRIPT_METHOD);
            boolean patternFound = EmailCleanUtils.patternFound(subject,
                    rejectPatterns);
            inputBinding.put(BINDING_PARAMS.GUARD_PASSED, !patternFound);
        }
        return inputBinding;
    }
}

The following parameter script for the above script shows how you can separate logic and configuration:

import java.util.LinkedList;
import java.util.List;
import java.util.regex.Pattern;
import com.aurel.track.util.emailHandling.EmailCleanUtils;

public class EmailGuardParams {
    private EmailGuardParams() {
        List<String> rejectStrings = new LinkedList<String>();
        /******************Reject subject strings************************/
        // the regEx which if found in email subject no item/comment will
        // be added
        rejectStrings.add("Undelivered Mail Returned to Sender");
        rejectStrings.add("außer Haus");
        rejectStrings.add("out of.*?house");
        rejectStrings.add("out of.*?office");
        rejectStrings.add("be out of the office");
        /***********Do not modify after this line **********************/
        rejectPatterns =  EmailCleanUtils.compilePatterns(rejectStrings);
    }
    private static EmailGuardParams instance = null;
    private static List<Pattern> rejectPatterns;
    public static EmailGuardParams getInstance() {
        if (instance == null) {
            instance = new EmailGuardParams();
        }
        return instance;
    }
    public static List<Pattern> getRejectPatterns() {
        return rejectPatterns;
    }
}