This is a common issue with custom JavaScript actions in AEC 2021 workflow automation. The problem stems from how workflow actions are bound to form events and executed within the workflow engine context. Here’s what you need to fix:
1. Form Event Binding
Your current code uses ‘onFormSubmit’ as the trigger, but this event binding doesn’t exist in the workflow automation context. AEC 2021 workflows use a different event model than standalone forms:
workflow.addAction('custom-js', {
script: 'validateLeadScore',
trigger: 'workflow.step.complete',
executionContext: 'client'
});
The key changes:
trigger: 'workflow.step.complete' - This is the correct workflow-level event that fires after form submission
executionContext: 'client' - Specifies that the script should run in the browser context (default is ‘server’, which has different API access)
2. Workflow Automation Logs
Custom JS actions that fail silently usually have execution errors that only appear in the workflow automation logs, not the browser console. To view these:
- Navigate to Workflow Automation → Monitoring → Execution Logs
- Filter by your workflow name and date range
- Look for entries with type ‘CustomActionExecution’
- Expand the log entry to see the detailed error message
Common errors include:
- Script not found in registry (script name mismatch)
- Insufficient permissions to execute custom scripts
- Timeout errors (default timeout is 5 seconds)
- Sandbox violations (accessing restricted APIs)
3. JS Action Execution Requirements
For custom JS actions to execute properly in workflows, you need to complete these setup steps:
Step 1: Register the script
// In Workflow Automation → Scripts → Custom Actions
// Register your script with proper metadata
{
name: 'validateLeadScore',
description: 'Validates lead score before workflow proceeds',
version: '1.0',
timeout: 10000,
requiredPermissions: ['workflow.execute', 'data.read']
}
Step 2: Configure form data binding
The script needs access to form data. In your workflow step configuration:
workflowStep.setDataBinding({
formData: 'step.input.formData',
outputVariable: 'leadScoreValidation'
});
Step 3: Update the action registration
workflow.addAction('custom-js', {
script: 'validateLeadScore',
trigger: 'workflow.step.complete',
executionContext: 'client',
inputMapping: {
formData: '${step.input.formData}',
currentScore: '${lead.score}'
},
outputMapping: {
isValid: 'leadScoreValidation.isValid',
validationMessage: 'leadScoreValidation.message'
}
});
The input/output mapping tells the workflow engine how to pass data to your script and where to store the results.
Testing and Debugging:
- Enable verbose logging: Workflow Settings → Debug Mode → Enable
- Test the workflow with a single instance to see detailed execution logs
- Verify the script executes: Check for ‘Script executed successfully’ in logs
- If the script still doesn’t run, check user permissions: Admin Console → Roles → Workflow Automation → Custom Script Execution
Common Pitfalls:
- Script name in
addAction() must exactly match the registered script name (case-sensitive)
- The workflow must be republished after adding custom actions (draft changes don’t affect running workflows)
- Form-based triggers like ‘onFormSubmit’ only work in standalone forms, not workflow forms
- Client-side execution context has access to browser APIs but not to server-side workflow variables
If you’re still having issues after these changes, share the workflow automation log entries for the specific workflow instance, and I can help diagnose the exact failure point.