🧭 Get Line Manager Until CEO in Joget Using BeanShell

java dev.to

1. Overview

βœ… This Joget snippet helps you decide who the next approver should be based on whether a request is escalated or not.

βœ… If the item is not escalated, the script takes the requester’s higher-level manager and stores it as the next line manager.

βœ… If the item is already escalated, the script keeps moving up the hierarchy by using the previously stored manager value.

βœ… In real workflows, this is useful when approval paths depend on organizational levels instead of a fixed list of users.

2. How It Works

βš™οΈ The script reads a form field that tells Joget whether the record is escalated.

βš™οΈ If the value is not Yes, it fetches the manager information from the requestor and saves two workflow variables:

βš™οΈ LineManager for the next approver email.

βš™οΈ CurrentLineManager for the username of the current hierarchy level.

βš™οΈ If the value is Yes, the script reuses the previously stored CurrentLineManager and moves one step higher.

βš™οΈ The idea is simple: keep pushing the workflow to the right person without hardcoding the approval chain in every step.

3. Full Code

import org.joget.commons.util.LogUtil;
import org.joget.workflow.model.service.WorkflowManager;

public void getLineManager() {
    WorkflowManager workflowManager = (WorkflowManager) pluginManager.getBean("workflowManager");

    // Replace these placeholders with your own form and user hash variables.
    String escalatedValue = "#form.your_form.escalated#";

    LogUtil.info("Line Manager Blog", "Escalated value: " + escalatedValue);

    if (!"Yes".equalsIgnoreCase(escalatedValue)) {
        String managerEmail = "#user.{variable.requestor}.manager.email#";
        String managerUsername = "#user.{variable.requestor}.manager.username#";

        LogUtil.info("Line Manager Blog", "Initial manager email: " + managerEmail);

        workflowManager.activityVariable(workflowAssignment.getActivityId(), "LineManager", managerEmail);
        workflowManager.activityVariable(workflowAssignment.getActivityId(), "CurrentLineManager", managerUsername);
    } else {
        String currentManager = "#variable.CurrentLineManager#";
        String nextManagerEmail = "#user.{variable.CurrentLineManager}.email#";

        LogUtil.info("Line Manager Blog", "Current manager: " + currentManager);

        workflowManager.activityVariable(workflowAssignment.getActivityId(), "LineManager", nextManagerEmail);
    }
}

getLineManager();
Enter fullscreen mode Exit fullscreen mode

4. Example Use Cases

βœ… Multi-level approval chains where each escalation step goes to the next manager.

βœ… HR or compliance flows where the approver depends on who submitted the form.

βœ… Internal request routing where the next reviewer changes after each escalation.

βœ… Cases where you want a simple and traceable approval path without building a separate routing table.

5. Customization Tips

πŸ’‘ Replace #form.your_form.escalated# with your real Joget form field.

πŸ’‘ If your hierarchy uses department heads, team leads, or role-based routing, adjust the hash variables to match your directory structure.

πŸ’‘ If you want to go up more than one level, you can chain the logic and keep updating CurrentLineManager.

πŸ’‘ Keep the workflow variable names short and consistent so they are easy to reuse in later scripts.

6. Key Benefits

βœ… Less hardcoding in the workflow design.

βœ… Easier escalation handling for approval chains.

βœ… Cleaner maintenance when the organization structure changes.

βœ… Better reuse across similar Joget processes.

7. Security Note

⚠️ Do not publish real usernames, email domains, or internal hierarchy field names if they reveal your organization structure.

⚠️ If your project uses sensitive directory mappings, replace them with generic placeholders before sharing the article.

⚠️ Keep the logic public, but keep the real deployment values private.

8. Final Thoughts

βœ… This pattern is small, but it solves a common workflow problem very cleanly.

βœ… Once you have a reliable way to move from requestor to manager to higher manager, many approval flows become much easier to maintain.

βœ… The main thing to remember is to keep the hierarchy logic generic enough to reuse, but specific enough to remain readable.

πŸ’‘ Follow-up topic suggestion: Dynamic Manager Escalation in Joget With Conditional Workflow Variables

Source: dev.to

arrow_back Back to Tutorials