Scheduled Events
Scheduled Events let you run scripts on a recurring basis without any manual trigger. They're ideal for maintenance tasks, periodic reports, SLA enforcement, and data synchronization.
How Scheduling Works
ScriptFabric uses the Forge scheduledTrigger mechanism. The platform fires a scheduled trigger on an hourly interval, and ScriptFabric's Master Scheduler checks which jobs are due to run during that cycle.
Master Scheduler Behaviour
Each hourly cycle:
- The scheduler wakes up and queries all enabled jobs
- It identifies jobs whose next execution time has passed
- It runs up to 3 jobs per cycle (to stay within Forge execution limits)
- Each job processes via the Forge async queue with up to 14 minutes (840s) of execution budget and progress checkpointing
- Jobs that weren't run this cycle are queued for the next cycle
Important: Because the scheduler runs hourly and can only execute 3 jobs per cycle, scheduling many jobs for the same time may result in some being delayed to the next hour.
Event Configuration
Each scheduled event has:
| Field | Description |
|---|---|
| Name | Descriptive name for the event |
| Description | What the event does |
| Schedule | When to run (Interval, Weekly, Monthly, or Cron expression) |
| Script | JavaScript code to execute |
| Enabled | Toggle on/off |
Step-by-Step Guide: Configuring a Cron Job
Cron schedules allow you to define precise execution times using standard 5-part cron syntax and advanced business day rules.
Step 1: Navigate to Scheduled Events
- Open Jira and go to Apps → ScriptFabric.
- Select Scheduled Events from the sidebar navigation.
- Click the Create Job button at the top right of the page.
Step 2: Fill in Basic Job Details
- Name: Enter a clear, descriptive name for your job (for example, "First Business Day Executive Report").
- Description: Briefly describe what the scheduled script accomplishes.
- Run As: Choose whether the script executes as App User (recommended for administrative tasks) or Current User.
Step 3: Select Cron / Advanced Schedule Type
- In the Schedule Type selector bar, click Cron / Advanced.
- The Cron configuration panel will appear with an expression input field, quick preset buttons, and syntax reference guide.
Step 4: Enter your Cron Expression or Choose a Preset
You can type a custom 5-part cron expression or click one of the quick preset buttons:
- 1st Business Day of Month at 06:00 AM:
0 6 1W * * - Last Business Day of Month at 05:00 PM:
0 17 LW * * - Every Weekday Mon to Fri at 09:00 AM:
0 9 * * 1-5 - Every 15 Minutes:
*/15 * * * * - First Day of Month at Midnight:
0 0 1 * * - Every Night at Midnight:
0 0 * * *
Cron Field Reference Structure
A 5-part cron expression follows this exact order:
[Minute] [Hour] [Day of Month] [Month] [Day of Week]
| Field | Allowed Values | Special Modifiers |
|---|---|---|
| Minute | 0 to 59 | *, */n, 0-30 |
| Hour | 0 to 23 | *, */n, 9-17 |
| Day of Month | 1 to 31 | 1W (nearest business day), LW (last business day), L (last day) |
| Month | 1 to 12 or JAN to DEC | *, 1-6, JAN,JUL |
| Day of Week | 0 to 7 (0 and 7 = Sun) or SUN to SAT | 1-5 (Mon to Fri), 5#1 (1st Friday of month) |
Special Business Day Rules Explained
1W: Runs on the nearest business day to the 1st of the month. If the 1st is Saturday, it runs on Monday the 3rd. If the 1st is Sunday, it runs on Monday the 2nd. If the 1st is Monday to Friday, it runs on the 1st.LW: Runs on the last business day of the month (Friday if the month ends on Saturday or Sunday).L: Runs on the last calendar day of the month (28th, 29th, 30th, or 31st).
Step 5: (Optional) Set Timezone and Active Time Frame
- Timezone: Select your preferred IANA timezone (such as America/New_York or UTC). All cron times evaluate relative to this timezone.
- Start Date and End Date: Set an optional date range when the schedule is active.
- Allowed Months: Optionally restrict execution to specific months (for example, run only in June and December).
Step 6: Write or Paste your Automation Script
Enter your JavaScript or Canarys HAPI script in the code editor. You can also select a starter snippet from the pre-built template dropdown.
Step 7: Save and Verify Next Run Time
- Click Save Job.
- ScriptFabric calculates and displays the exact Next Run At timestamp based on your cron expression and timezone.
- You can click Run Now at any time to test your script immediately without waiting for the next scheduled trigger.
Real-World Scenarios
Scenario: Close stale issues weekly
// Find issues untouched for 30+ days in "Waiting for Customer" status
const stale = WorkItems.search(
'status = "Waiting for Customer" AND updated < -30d'
);
let closed = 0;
await stale.forEach(async (issue) => {
await issue.addComment('Closing due to 30 days of inactivity. Reopen if still needed.');
await issue.transition('Closed');
closed++;
});
return `Closed ${closed} stale issues`;
Scenario: Generate a daily summary
const created = await WorkItems.count('created >= -1d');
const resolved = await WorkItems.count('resolved >= -1d');
const bugs = await WorkItems.count('type = Bug AND created >= -1d');
console.log('=== Daily Summary ===');
console.log(`Created: ${created}`);
console.log(`Resolved: ${resolved}`);
console.log(`New bugs: ${bugs}`);
Scenario: Enforce SLA - escalate overdue issues
const overdue = WorkItems.search(
'due < now() AND status != Done AND priority = High'
);
await overdue.forEach(async (issue) => {
await issue.update(b => b.setPriority('Critical'));
await issue.addComment('⚠️ SLA breach - priority escalated to Critical.');
});
Execution Limits
| Constraint | Value |
|---|---|
| Minimum interval | 1 hour (Forge platform limitation) |
| Jobs per cycle | 3 |
| Time budget per job | ~22 seconds |
| Script size limit | 100 KB |
Viewing Event History
Each event execution is logged in Activity Log with the feature type "Scheduled Event". You can filter to see:
- Which events ran and when
- Success/failure status
- Console output from each run
- Duration of execution