Pre-fill Forms from URL Parameters
Load user context and pre-populate forms when they open
Launch workflows (also called startup workflows) run when a form loads to fetch data and make it available throughout the form. Use them to pre-fill fields, check permissions, or load context.
What You’ll Build
Section titled “What You’ll Build”A customer feedback form that:
- Loads customer details from URL parameter
- Pre-fills customer name and email
- Shows personalized welcome message
Create Launch Workflow
Section titled “Create Launch Workflow”Create a workflow that accepts a parameter and returns data (workspace/workflows/load_customer.py):
from bifrost import workflow, param, ExecutionContext
@workflow(name="load_customer_data", description="Load customer for feedback form")@param("customer_id", type="string", required=True)async def load_customer_data(context: ExecutionContext, customer_id: str): """Load customer data for pre-filling form."""
# Fetch customer from database customer = await get_customer(context, customer_id)
return { "customer_name": customer.name, "customer_email": customer.email, "purchase_date": customer.last_purchase_date, "product_name": customer.last_product }Configure Form
Section titled “Configure Form”- Open form in builder
- Right panel → Launch Workflow section
- Select
load_customer_data
Allow URL Parameter
Section titled “Allow URL Parameter”To pass customer_id via URL:
- Add form field:
customer_id(hidden text field) - Enable Allow as Query Parameter on the field
- Save form
Now you can use: /execute/form?customer_id=cust-123
Use Workflow Data
Section titled “Use Workflow Data”Display in HTML Content
Section titled “Display in HTML Content”Show workflow data using HTML Content fields:
<div className="p-4 bg-blue-50 rounded-lg border border-blue-200"> <h2 className="font-bold text-lg"> Welcome back, {context.workflow.customer_name}! </h2> <p className="text-sm text-gray-700"> We see you purchased {context.workflow.product_name} on{" "} {context.workflow.purchase_date}. We'd love to hear your feedback! </p></div>Control Field Visibility
Section titled “Control Field Visibility”Show fields based on workflow data:
// Show VIP feedback field only for premium customerscontext.workflow.customer_tier === "premium";Common Use Cases
Section titled “Common Use Cases”Check User Permissions
Section titled “Check User Permissions”@workflow(name="check_permissions")async def check_permissions(context: ExecutionContext): """Check if user can access form."""
return { "is_admin": context.is_platform_admin, "user_email": context.email, "can_approve": await has_permission(context, "approve_requests") }Use in form visibility rules to show admin-only fields.
Load Organization Context
Section titled “Load Organization Context”@workflow(name="load_org_context")async def load_org_context(context: ExecutionContext): """Load organization details."""
org = await get_organization(context, context.org_id)
return { "org_name": org.name, "org_plan": org.subscription_plan, "org_features": org.enabled_features }Use to display org info or control feature availability.
Pre-fill from External System
Section titled “Pre-fill from External System”@workflow(name="load_ticket_data")@param("ticket_id", type="string", required=True)async def load_ticket_data(context: ExecutionContext, ticket_id: str): """Load ticket details for follow-up form."""
ticket = await fetch_ticket_from_psa(context, ticket_id)
return { "ticket_number": ticket.number, "customer_name": ticket.customer, "issue_description": ticket.description, "priority": ticket.priority }Pre-fill form with existing ticket details for follow-up.
Default Parameters
Section titled “Default Parameters”Provide default values when URL params aren’t provided:
- In form settings → Default Launch Parameters
- Enter JSON:
{ "include_history": true, "limit": 10}These are used when parameters aren’t in the URL.
Testing
Section titled “Testing”Test launch workflow before using in form:
- Click Play button next to Launch Workflow in form builder
- Enter test parameters
- Click Execute
- View returned data
- Verify all expected fields are present
Troubleshooting
Section titled “Troubleshooting”Form won’t load: Launch workflow has required parameters but no default values or URL params provided. Add defaults or pass via URL.
Data not appearing: Click Info button in form builder to see context.workflow object. Verify workflow returns expected fields.
Workflow fails: Check workflow logs for errors. Verify parameters are correct type and external APIs are accessible.
Parameters not working: Ensure form field with same name exists and has “Allow as Query Parameter” enabled.
Best Practices
Section titled “Best Practices”- Keep workflows fast - They block form load. Avoid slow API calls or heavy processing.
- Return only needed data - Don’t fetch entire objects if you only need a few fields.
- Handle missing data - Return sensible defaults if external system returns null.
- Use caching - Cache expensive lookups to speed up repeated form loads.
- Test independently - Test launch workflow with Play button before using in form.
Example: Complete Survey Form
Section titled “Example: Complete Survey Form”@workflow(name="load_survey_context")@param("customer_id", type="string", required=True)async def load_survey_context(context: ExecutionContext, customer_id: str): """Load customer context for satisfaction survey.""" customer = await get_customer(context, customer_id)
return { "customer_name": customer.name, "customer_email": customer.email, "last_purchase": customer.last_purchase_date, "product_name": customer.last_product_name, "is_premium": customer.tier == "premium" }<div className="p-6 bg-blue-50 rounded-lg border border-blue-200 mb-4"> <h2 className="font-bold text-xl mb-2"> Hi {context.workflow.customer_name}! 👋 </h2> <p className="text-gray-700"> Thank you for purchasing {context.workflow.product_name}. We'd love to hear about your experience! </p></div>- Create hidden field
customer_id - Enable “Allow as Query Parameter”
- Set Launch Workflow to
load_survey_context - Add HTML Content field with welcome message (uses
context.workflow.*) - Add visibility rules to show/hide fields based on
context.workflow.is_premium - Share link:
/execute/form?customer_id=cust-123
Note: To pre-fill name/email fields, pass them as query parameters: ?customer_id=123&name=John&email=john@example.com
Next Steps
Section titled “Next Steps”- Display Personalized Welcome Messages - Use workflow data in HTML
- Show Fields Based on User Permissions - Control visibility with workflow data
- Cascading Dropdowns - Use workflow data in dropdowns