Script Definitions#
Create, manage, and organize your custom JavaScript scripts in Automan.
Overview#
Script Definitions are the core building blocks of Automan. A definition contains:
- Name - A descriptive name for the script
- Description - Optional documentation about what the script does
- JavaScript Code - The actual script that executes
- Triggers - Optional event triggers that execute the script
- Cron Schedule - Optional scheduled execution configuration
Definitions can be used in multiple contexts:
- Workflow post functions
- Automation actions
- Event triggers
- Scheduled (cron) jobs
Accessing Definitions#
- Navigate to
Apps>Automan - The Definitions tab is the default view
Creating a Definition#
Step 1: Start Creation#
Click the New Definition button in the top right corner.
Step 2: Fill in Details#
- Name (required) - Enter a descriptive name
- Description (optional) - Add documentation about the script’s purpose
Step 3: Write Code#
Use the JavaScript code editor to write your script. The editor provides:
- Syntax highlighting
- Line numbers
Step 4: Configure Triggers (Optional)#
Select event triggers to automatically execute this script when events occur:
Step 5: Test the Script#
Click Run Script to test your code before saving:
Step 6: Save#
Click Save to create the definition.
Editing a Definition#
- Click on a definition row in the list
- Make your changes
- Click Save
Changes are saved as a new version, preserving the history.
Definition Tags#
Definitions automatically display tags showing how they are used:
| Tag | Color | Meaning |
|---|---|---|
| workflow | Blue | Used in a workflow post function |
| automation | Orange | Used in an automation action |
| cron | Green | Has cron scheduling enabled |
| Event Name | Red | Subscribed to an event trigger |
Bulk Operations#
Selecting Multiple Definitions#
- Use the checkboxes on the left to select definitions
- Or use the header checkbox to select all
Bulk Duplicate#
- Select one or more definitions
- Click Duplicate (N) button
- Confirm the operation
New definitions are created with “(Copy)” appended to the name.
Bulk Delete#
- Select one or more definitions
- Click Delete (N) button
- Confirm the operation
Warning: Deletion is permanent and cannot be undone.
Version History#
Automan automatically saves a new version each time you modify a definition’s code.
Viewing History#
- Edit a definition
- Click the History tab
- View the list of versions with timestamps and authors
Viewing Version Code#
- Click View Code on any version row
- A modal shows the code from that version
Restoring a Previous Version#
To restore a previous version:
- View the code from the history
- Copy the code
- Go to the General tab
- Paste the code
- Save
Searching Definitions#
Use the search box to filter definitions by name:
- Type in the search field
- Results filter in real-time
- Clear the search to show all definitions
Code Editor Features#
The Automan code editor provides several features to help you write scripts:
JavaScript Support#
- Most of ES2023+ syntax support
- Async/await support
- Modern JavaScript features
Available Globals#
The following globals are available in your scripts:
| Global | Description |
|---|---|
event |
The event/context object containing trigger data |
console.log() |
Log messages for debugging |
requestJira() |
Make Jira REST API calls |
route |
Template tag for building API routes |
process.env |
Access environment variables |
URLSearchParams |
Build query strings |
Example Script Structure#
// Log the event for debugging
console.log("Event received:", event);
// Access environment variables
const apiKey = process.env.MY_API_KEY;
// Make a Jira API call
const response = await requestJira(
route`/rest/api/3/myself`
);
const user = await response.json();
console.log("Current user:", user.displayName);
// Return a value (for automation actions)
{ success: true, user: user.displayName };Testing Scripts#
Before deploying, test your scripts using the Run Script button.
Test Results#
After running a test, you’ll see:
- Status - Success or Failed
- Duration - Execution time in milliseconds
- Console Output - All
console.log()messages - Return Value - The script’s return value (if any)
- Error - Error message and stack trace (if failed)
Test Event Object#
When testing, the event object contains:
{
type: "test"
}For more realistic testing, you may need to manually fetch data:
// Simulate testing with a specific work item
const testIssueKey = "PROJ-123";
const response = await requestJira(route`/rest/api/3/issue/${testIssueKey}`);
const issue = await response.json();
// Now work with the work item data
console.log("Testing with work item:", issue.key);Definition States#
A definition can be in various states based on its configuration:
Active Definition#
- Has code saved
- May have triggers, cron, or be used in workflows/automations
- Will execute when triggered
Empty Definition#
- No code saved
- Will not execute even if triggers are configured
- Useful as a placeholder
Orphaned Definition#
- Not used in any workflow post function or automation
- No triggers or cron configured
- May be a candidate for deletion
Best Practices#
Naming Conventions#
- Use descriptive names: “Auto-assign high priority work items” instead of “Script 1”
- Include the context: “Workflow: Close subtasks on parent resolution”
- Prefix by area: “Report: Weekly status summary”
Documentation#
- Use the description field to document purpose and behavior
- Add comments in code for complex logic
- Note any dependencies (environment variables, custom fields)
Organization#
- Group related scripts with similar naming prefixes
- Use tags (shown automatically) to understand usage
- Regularly review and clean up unused definitions
Code Quality#
- Handle errors gracefully with try/catch
- Log meaningful messages for debugging
- Avoid hardcoding values - use environment variables
- Test before deploying
Troubleshooting#
Definition Not Executing#
- Check that code is saved (not empty)
- Verify triggers are configured correctly
- For workflow/automation, ensure the definition is properly linked
- Review the Executions tab for errors
Related Topics#
- Workflow Post Functions - Using definitions in workflows
- Automation Actions - Using definitions in automation rules
- Event Triggers - Subscribing to Jira events
- Scheduled Scripts - Running scripts on a schedule
- Environment Variables - Managing secrets and configuration