

When designing workflows, it’s easy to focus on simply connecting steps: request → approve → done. But in practice, even a simple process like leave requests can create complications:
- Managers approve requests that later turn out to be problematic
- Team schedules become unbalanced
- Back-and-forth increases when dates need to be changed
In this article, a “smart” leave request workflow in Questetra BPM Suite is presented—using standard BPMN icons and a small amount of coding—to reduce these issues before they occur.
The core principle is as follows:
Complex logic is not required for a functional workflow; rather, necessary checks must be performed at appropriate intervals.
The Goal of a Smart Leave Workflow
Beyond simple collection and approval, the following objectives are prioritized:
- Prevent invalid or problematic requests early
- Reduce unnecessary manual checks
- Handle delays automatically
- Keep the process simple for users
Overview of the Workflow
The overall structure is defined as follows:
- Human Task: Enter Leave Details
- Script Task: Check Calendar Availability
- Exclusive Gateway: Is the Date Available?
- Human Task: Manager Approval
- Timer Boundary Event: Escalation
- Google Calendar: Insert Event / Throwing Message Intermediate Event (email): Updates and Notifications

Each step is analyzed from a design perspective below.
1. Human Task – Capturing the Right Information
The first step is a Human Task where the requester fills in the required details.
Typical inputs:
- Leave dates
- Reason
- Backup contact
Design tip: Keep the form simple. The easier it is to submit, the more consistently the app will be used.

The following standard should be observed:
Effective workflows ensure the collection of accurate data at the onset of the process.
2. Script Task – Checking Calendar Availability
This is where the workflow becomes “smart”.
Instead of waiting for a manager to manually check schedules, an Auto Step (Script Task) can be inserted to check whether the requested date is already heavily booked.
What this step does:
- Looks at the requested date
- Checks a calendar system (in this case Google Calendar)
- Determines whether the date is “full” or still available
Implementation Note: As a dedicated BPMN icon for calendar verification does not exist, a Script Task is utilized to invoke an external service and evaluate availability.
Technical details regarding the Script Task may be referenced in the provided code block below.
Script (click to open)
/*
* Questetra Script Task
* Check whether the requested leave period overlaps with existing Google Calendar events
*
* Input:
* q_start_date (Date)
* q_end_date (Date)
*
* Output:
* q_availability (Select, single choice)
* - option ID: YES
* - option ID: NO
*
* Important:
* - Replace CALENDAR_ID
* - Replace ACCESS_TOKEN retrieval with your real method
* - This assumes the Select item q_availability has option IDs exactly "YES" and "NO"
*/
const CALENDAR_ID = "YOUR CALENDAR ID";
// 1) Read dates from workflow data items
const startDate = engine.findDataByVarName("q_start_date");
const endDate = engine.findDataByVarName("q_end_date");
if (startDate === null || endDate === null) {
throw new Error("q_start_date or q_end_date is empty.");
}
// 2) Build an inclusive date-time range
// Start at 00:00:00 of start date
// End at 23:59:59 of end date
const timeMin = startDate.toString() + "T00:00:00+09:00";
const timeMax = endDate.toString() + "T23:59:59+09:00";
// 3) Build Google Calendar Events API request
const url =
"https://www.googleapis.com/calendar/v3/calendars/" +
encodeURIComponent(CALENDAR_ID) +
"/events";
let request = httpClient.begin();
request = request.authSetting("YOUR APP NAME");
request = request.queryParam("timeMin", timeMin);
request = request.queryParam("timeMax", timeMax);
request = request.queryParam("singleEvents", "true");
request = request.queryParam("orderBy", "startTime");
const response = request.get(url);
const status = response.getStatusCode() + "";
const body = response.getResponseAsString() + "";
engine.log("Calendar check status: " + status);
if (status !== "200") {
throw new Error("Google Calendar API error: " + status + "\n" + body);
}
// 4) Parse response
const json = JSON.parse(body);
const events = json.items || [];
// 5) Decide availability
// If any event exists in the requested period, mark as NO
const availableFlag = (events.length === 0) ? "YES" : "NO";
// 6) Save to Select-type data item q_availability
const result = new java.util.ArrayList();
result.add(availableFlag);
engine.setDataByVarName("q_availability", result);
engine.log("Leave availability: " + availableFlag);
engine.log("Events found: " + events.length);
Functional code can be generated by AI to meet specific requirements, facilitating complex automation for workflow designers.
3. Exclusive Gateway – Is the Date Available?
Following the Auto Task, an Exclusive Gateway (XOR-Split) is used to branch the workflow based on date availability:
- Date available → proceed to approval
- Date full → return to requester

The following design principle is applied:
Workflow intelligence is maximized when decisions are executed early in the process.
Note: following the Gateway there is an [Update Data] step called “Update Datetime”. This simply converts the dates input in the “Start Date” and End Date” fields into Datetime-type data items, which allows them to be selected later in the workflow in the [Google Calendar: Insert Event] steps. This is necessary to allow the approved request to be inserted into the external calendar.
4. Human Task – Manager Approval
If the date is valid, the request moves to a Manager Approval (Human Task).
At this point:
- Focus is placed on decision-making rather than data validation
- The process is faster and cleaner
Design insight: The cognitive load on approvers is reduced by the early filtering of problematic requests.
5. Timer Boundary Event – Handling Delays Automatically
Delays are frequently encountered in approval workflows.
A Timer Boundary Event is attached to the approval task to address this:
- If the manager doesn’t respond within a set time (e.g. 2 days)
→ Automatically escalate to another approver (in this case the Department Head)
Utilizing this approach transforms the workflow to be:
- Highly dependable
- Resilient against individual bottlenecks
An Error Boundary Event can also be configured to escalate the task if no eligible user is available.
6. Auto Steps – Updates and Notifications
Upon approval, a Google Calendar: Insert Event is executed to:
- Update a calendar using the dates input by the requester
Meanwhile, a Throwing Message Intermediate Event (email) is used to:
- Send confirmation emails
- Notify relevant team members
These system-level responsibilities are ideal for Auto Steps.
The workflow concludes either with the scheduling of the approved leave or the rejection of the request.
What Makes This Workflow “Smart”?
In spite of the simplicity, significant improvements are introduced by this design:
1. Problems are caught early
Calendar conflicts are detected before approval
2. Manual work is reduced
Manual availability checks by managers are eliminated.
3. Delays are handled automatically
Progress is ensured through automated escalation.
4. The process stays user-friendly
No additional burden is placed on employees.
Key Takeaway for Workflow Designers
During the design phase, it was noted that a specific BPMN icon for calendar verification is unavailable.
BPMN focuses on the modeling of responsibility rather than specific actions:
- Human Tasks represent points where actions or decisions are performed by personnel
- Auto Tasks represent points where functions or logic are applied by the system
- Gateways control the case flow based on the outcomes of these steps
In this workflow, the availability check is performed via a Script Task, where requested dates are evaluated against defined criteria. The Gateway then routes the process accordingly.
For a workflow designer, importance is placed on defining where decisions are made, identifying responsible entities, and determining the subsequent process flow.
Summary
Workflow optimization is achievable through simple design changes.
Business processes like leave requests are improved by the strategic placement of Auto Steps and the careful analysis of decision points.
Conclusion:
These improvements are accessible to workflow designers without extensive technical expertise.
Detailed information regarding Auto Tasks, Script Tasks, and API integrations may be found in the associated developer blog series.
Articles in This Series
- Building a Leave Request Workflow with Scripts (Overview) (this article)
- Building a Leave Request Workflow with Scripts (Calendar Verification)
- Building a Leave Request Workflow with Scripts (Alternative Date Suggestion)


