Calling server script method in client script

Iam trying to call a method in client script, which is present in server script.

While iam doing this, iam getting error like below…

Screenshot from 2024-02-10 11-42-23

please help me to do this…

I will provide my client script and server script if needed…

Thanks in advance

because the download method isn’t in the
If you define the download, please check the path to the client script.

Thank You!

@NCP Thanks for your reply…

this is my server script code (

def download(docname):
document = frappe.get_doc(‘Sales Invoice’,{“name”:docname})
html_content = frappe.get_print(‘Sales Invoice’,, print_format=‘Sales Invoice Custom Print’)
pdf = frappe.utils.pdf.get_pdf(html_content)
desktop_path = os.path.expanduser(“~/Downloads”)
current_datetime =“%Y-%m-%d_%H:%M:%S”)
file_name = f"{name}_{current_datetime}.pdf"
file_path = os.path.join(desktop_path, file_name)
# Save the PDF file
with open(file_path, “wb”) as f:
return file_path

This is my client script code (sales_invoice.js)…

frappe.ui.form.on(‘Sales Invoice’, {
refresh: function (frm) {
frm.add_custom_button((‘Download Print’), function () {{
method: ‘’,
args: {
callback: function (r) {
if (r.message) {
(‘Download successfully.’));

the file paths are :::

for server script : /home/kiranmai/Downloads/Hilltop/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/

for client script : /home/kiranmai/Downloads/Hilltop/frappe-bench/apps/erpnext/erpnext/accounts/doctype/sales_invoice/sales_invoice.js

please check the reference so you can understand of define the and

Please check the set_missing_values method

How to call in the

Frappe Ajax Call reference documentation.

I hope this helps.

Thank You!

@NCP Its Wroking… Thank you