Client Scripts in iVendNext allow users to customize and extend the functionality of forms dynamically. These JavaScript-based snippets enable real-time modifications—such as hiding buttons, validating fields, or triggering actions—without altering core system files.
Key Use Cases:
Rename or hide form buttons (e.g., "Create" submenu options).
Validate data before submission (e.g., enforce mandatory fields).
Automate UI updates based on user input.
Navigate to: Home > Customization > Custom Script.
Click New to create a script.
Select the DocType (e.g., "Sales Order") to target.
Client scripts use the ivendnext.ui.form.on method to bind actions to form events. Example:
ivendnext.ui.form.on('Sales Order', {
refresh: function(frm) {
// Actions to execute when the form loads
console.log("Form refreshed!");
}
});
Key Events:
refresh: Triggers when the form loads or reloads.
onload_post_render: Runs after the form renders completely.
validate: Validates data before submission.
To hide the "Update Items" and "Close" buttons in a Sales Order:
ivendnext.ui.form.on('Sales Order', {
refresh: function(frm) {
setTimeout(() => {
frm.remove_custom_button('Update Items');
frm.remove_custom_button('Close', 'Status');
}, 10);
}
});
Replace default options like "Delivery" with custom labels:
ivendnext.ui.form.on('Sales Order', {
onload_post_render: function(frm) {
const buttons = ['Delivery', 'Invoice', 'Work Order'];
buttons.forEach(button => {
frm.page.remove_inner_button(button, 'Create');
});
frm.page.add_inner_button('Generate Invoice', () => {
// Add custom function here
}, 'Create');
}
});
Prevent submission if a field is empty:
ivendnext.ui.form.on('Quotation', {
validate: function(frm) {
if (!frm.doc.customer) {
ivendnext.msgprint("Customer field is mandatory!");
frappe.validated = false;
}
}
});
Clear Cache: After saving scripts, go to Tools > Clear Cache and refresh.
Browser Console: Use console.log() to debug scripts (press F12 to open DevTools).
Test Incrementally: Add small script portions and verify changes.
Limit Scripts: Overuse can slow down forms.
Backup Scripts: Store copies in a repository for recovery.
Document Changes: Note script purposes for team reference.
Client Scripts unlock powerful UI customizations in iVendNext, from button tweaks to dynamic validations. Start with small changes and gradually explore advanced workflows.