To customize the UI in Frappe Helpdesk based on ticket type, you have several options. Here are the most effective approaches:
1. Client Scripts (Recommended)
Create a client script that triggers when the ticket type changes:
frappe.ui.form.on('HD Ticket', {
ticket_type: function(frm) {
set_ui_based_on_ticket_type(frm);
},
refresh: function(frm) {
set_ui_based_on_ticket_type(frm);
}
});
function set_ui_based_on_ticket_type(frm) {
let ticket_type = frm.doc.ticket_type;
// Hide all conditional fields first
frm.toggle_display('custom_field_1', false);
frm.toggle_display('custom_field_2', false);
frm.toggle_reqd('priority', false);
// Show/hide fields based on ticket type
if (ticket_type === 'Bug Report') {
frm.toggle_display('custom_field_1', true);
frm.toggle_reqd('priority', true);
frm.set_df_property('description', 'label', 'Bug Description');
}
else if (ticket_type === 'Feature Request') {
frm.toggle_display('custom_field_2', true);
frm.set_df_property('description', 'label', 'Feature Details');
}
else if (ticket_type === 'Support') {
frm.set_df_property('description', 'label', 'Issue Description');
}
}
2. Custom Form Layouts
Create different form layouts for each ticket type by using sections and conditional display:
frappe.ui.form.on('HD Ticket', {
ticket_type: function(frm) {
// Hide all sections first
frm.toggle_display('bug_section', false);
frm.toggle_display('feature_section', false);
frm.toggle_display('support_section', false);
// Show relevant section
if (frm.doc.ticket_type) {
frm.toggle_display(frm.doc.ticket_type.toLowerCase() + '_section', true);
}
}
});
3. Dynamic Field Properties
Modify field properties dynamically:
frappe.ui.form.on('HD Ticket', {
ticket_type: function(frm) {
let ticket_type = frm.doc.ticket_type;
// Change field options based on ticket type
if (ticket_type === 'Bug Report') {
frm.set_df_property('priority', 'options', ['Low', 'Medium', 'High', 'Critical']);
frm.set_df_property('status', 'options', ['Open', 'In Progress', 'Testing', 'Closed']);
} else if (ticket_type === 'Feature Request') {
frm.set_df_property('priority', 'options', ['Low', 'Medium', 'High']);
frm.set_df_property('status', 'options', ['Open', 'Under Review', 'Approved', 'In Development', 'Closed']);
}
}
});
4. Custom Doctype Approach
If you need significantly different forms, consider creating separate doctypes that inherit from HD Ticket or create custom fields with dependencies:
- Go to Customize Form for HD Ticket
- Add custom fields with "Depends On" conditions
- Set dependency like:
eval:doc.ticket_type=="Bug Report"
5. Portal Customization
For customer-facing forms, customize the web form:
// In web form script
frappe.ready(function() {
$('[data-fieldname="ticket_type"]').on('change', function() {
let ticket_type = $(this).val();
if (ticket_type === 'Bug Report') {
$('[data-fieldname="steps_to_reproduce"]').show();
$('[data-fieldname="expected_behavior"]').show();
} else {
$('[data-fieldname="steps_to_reproduce"]').hide();
$('[data-fieldname="expected_behavior"]').hide();
}
});
});
Implementation Steps:
- Navigate to: Desk → Customize → Client Script
- Create New Client Script for DocType "HD Ticket"
- Add your conditional logic using the examples above
- Test thoroughly with different ticket types
- Apply to web forms if needed for customer portal
The client script approach is usually the most flexible and maintainable solution for this type of UI customization in Frappe Helpdesk.