🧭 Get Line Manager Until CEO in Joget Using BeanShell

# automation# java# programming# tutorial
🧭 Get Line Manager Until CEO in Joget Using BeanShellExplorer

1. Overview ✅ This Joget snippet helps you decide who the next approver should be based on...

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