How to trigger export on custom button click?

I have a script report. Just like any other report I can export its data (rows/columns) in excel or csv format.
I have a custom button in this script report called “Non Redundant Export”. How can I trigger the original export button’s functionality when I click on my custom button.

Any help is appreciated.

Use Reference of Frappe Team Code to achieve your Customisation.
Find this function def export_query(): and look the code

1 Like

@pra17shant Thanks for your help.

Any Time

Hello Prashant…

I added button “Export” using client script.

Now I am not able to add this function to that Button.

def export_query():
	"""export from report builder"""
	from frappe.desk.utils import get_csv_bytes, pop_csv_params, provide_binary_file

	form_params = get_form_params()
	form_params["limit_page_length"] = None
	form_params["as_list"] = True
	doctype = form_params.pop("doctype")
	file_format_type = form_params.pop("file_format_type")
	title = form_params.pop("title", doctype)
	csv_params = pop_csv_params(form_params)
	add_totals_row = 1 if form_params.pop("add_totals_row", None) == "1" else None

	frappe.permissions.can_export(doctype, raise_exception=True)

	if selection := form_params.pop("selected_items", None):
		form_params["filters"] = {"name": ("in", json.loads(selection))}

	make_access_log(
		doctype=doctype,
		file_type=file_format_type,
		report_name=form_params.report_name,
		filters=form_params.filters,
	)

	db_query = DatabaseQuery(doctype)
	ret = db_query.execute(**form_params)

	if add_totals_row:
		ret = append_totals_row(ret)

	data = [[_("Sr")] + get_labels(db_query.fields, doctype)]
	data.extend([i + 1] + list(row) for i, row in enumerate(ret))
	data = handle_duration_fieldtype_values(doctype, data, db_query.fields)

	if file_format_type == "CSV":
		from frappe.utils.xlsxutils import handle_html

		file_extension = "csv"
		content = get_csv_bytes(
			[[handle_html(frappe.as_unicode(v)) if isinstance(v, str) else v for v in r] for r in data],
			csv_params,
		)
	elif file_format_type == "Excel":
		from frappe.utils.xlsxutils import make_xlsx

		file_extension = "xlsx"
		content = make_xlsx(data, doctype).getvalue()

	provide_binary_file(title, file_extension, content)

Also, after adding button Export to ListView Actual Export Button in dropdown gets hide as below.

Hi, @umarless

Even I am trying to achieve the same. Did you find the solution?