⚙️ ERPNext Client Script Generator
Generate ERPNext client scripts instantly. Templates for common events like onload, refresh, validate, and custom buttons.
Script Settings
Generate boilerplates for ERPNext client scripts.
Client Script
Ready-to-use JavaScript for Frappe.
Configure settings to generate a client script boilerplate.
How to Use the ERPNext Script Generator
- Enter DocType: The name of your ERPNext DocType (e.g., "Sales Order").
- Select Event: Choose when the script should run (onload, refresh, etc.).
- Add Field Name: For field-specific events, enter the field name.
- Generate: Get your ready-to-use client script template.
- Copy & Paste: Use in ERPNext → Customization → Client Script.
ERPNext Client Scripts Explained
ERPNext client scripts allow you to customize form behavior without modifying core code. They run in the browser and can validate data, show/hide fields, set values, and create custom buttons. Understanding the event lifecycle is key to effective customization.
Common Events
onload: Runs once when the form first loads. Use for initial setup like setting queries or default values. refresh: Runs every time the form refreshes (after save, after load). Use for conditional logic based on form state. validate: Runs before saving. Use for data validation and preventing invalid saves. Field Change: Runs when a specific field value changes. Use for dependent field logic.
Best Practices
Keep scripts simple and focused. Complex logic should be in server-side Python. Use frm.set_value() to update fields, frm.set_df_property() to change field properties, and frappe.msgprint() for user messages. Always test scripts thoroughly before deploying to production.
Frequently Asked Questions
What is an ERPNext client script?
ERPNext client scripts are JavaScript code that runs in the browser to customize form behavior without modifying core code. They can validate data, show/hide fields, set values, and create custom buttons.
When should I use onload vs refresh events?
Use onload for one-time setup when the form first loads (setting queries, default values). Use refresh for logic that needs to run every time the form refreshes, including after saves.
Can client scripts modify server-side data?
Client scripts run in the browser and can only modify form fields before saving. For server-side data modification, use server scripts or custom Python methods.
How do I add a custom button in ERPNext?
Use frm.add_custom_button() in the refresh event. Example: frm.add_custom_button('Button Label', function() ) creates a clickable button in the form toolbar.
Where do I paste the generated script?
Go to ERPNext → Customization → Client Script → New. Select your DocType, paste the generated script, and save. The script will automatically run on that DocType's forms.
