I want to create a custom button via client script that will create a new document (Communication).
What I don’t know is how to pass in the arguments (the fields values for the Communication) from the javascript to the custom method/server script.
My Client Script is
frappe.ui.form.on("Lead", "refresh", function(frm) {
frm.add_custom_button(__("Log Call"), function() {
// When this button is clicked, do this
let d = new frappe.ui.Dialog({
title: 'Enter details',
fields: [
{
label: 'Subject',
fieldname: 'subject',
reqd: 1,
fieldtype: 'Data'
},
{ fieldname:"section_break_1",
fieldtype: 'Section Break'
},
{
fieldname: 'column_break_1',
fieldtype: 'Column Break'
},
{
label: 'Direction',
fieldname: 'direction',
fieldtype: 'Select',
reqd: 1,
options: ['','Inbound','Outbound'],
},
{
fieldname: 'column_break_2',
fieldtype: 'Column Break'
},
{
fieldname:'section_break_2',
fieldtype: 'Section Break'
},
{
label: 'Message',
fieldname: 'message',
fieldtype: 'Long Text'
},
],
size: 'large', // small, large, extra-large
primary_action_label: 'Submit',
primary_action(values) {
frappe.call({
method: "communication_from_call",
args: {subject:frm.doc},
})
console.log(values);
d.hide();
}
});
d.show();
});
});
My Server Script (API) is
doc = frappe.new_doc('Communication')
doc.subject = 'Test Subject'
doc.communication_type = 'Communication'
doc.status = 'Open'
doc.sent_or_received = 'Sent'
doc.insert()```