Hi @falah123,
First, you need to learn the basic concepts and apply the client script. Just copying and pasting the code won’t solve the problem; you must understand how it works. There’s no benefit in copying and pasting without truly understanding it. You can’t rely on default settings every time.
This is a sample code
frappe.listview_settings['Contact'] = {
refresh: function(listview) {
listview.page.set_primary_action(__('+ Add Contact'), function() {
add_contact();
});
}
};
function add_contact() {
frappe.db.get_doc('DocType', 'Contact').then(doc => {
let fields = [
{
label: __('First Name'),
fieldname: 'first_name',
fieldtype: 'Data',
reqd: 1
},
{
fieldname: 'email_ids',
fieldtype: 'Table',
fields: [
{
label: __('Email ID'),
fieldname: 'email_id',
fieldtype: 'Data',
reqd: 1,
in_list_view: 1,
columns: 3
},
{
label: __('Is Primary'),
fieldname: 'is_primary',
fieldtype: 'Check',
in_list_view: 1,
columns: 2
}
],
data: []
},
{
fieldname: 'phone_nos',
fieldtype: 'Table',
fields: [
{
label: __('Number'),
fieldname: 'phone',
fieldtype: 'Data',
reqd: 1,
in_list_view: 1,
columns: 3
},
{
label: __('Is Primary Phone'),
fieldname: 'is_primary_phone',
fieldtype: 'Check',
in_list_view: 1,
columns: 2
},
{
label: __('Is Primary Mobile'),
fieldname: 'is_primary_mobile_no',
fieldtype: 'Check',
in_list_view: 1,
columns: 2
}
],
data: []
}
];
var dialog = new frappe.ui.Dialog({
title: __('Contact Entry'),
fields: fields,
primary_action: function() {
var values = dialog.get_values();
if (values) {
frappe.call({
method: 'frappe.client.insert',
args: {
doc: {
doctype: 'Contact',
first_name: values.first_name,
email_ids: values.email_ids,
phone_nos: values.phone_nos,
}
},
callback: function(r) {
if (!r.exc) {
frappe.msgprint(__('Contact Saved!'));
dialog.hide();
} else {
frappe.msgprint(__('Failed to save contact.'));
}
}
});
}
},
primary_action_label: __('Save')
});
dialog.show();
});
}