How to add Button to rows in Script Report?

I am trying to build a script report in which I want to a button in the last column of each row and when a user clicks on the button want to show a modal dialog with data from another DocType.

I tried adding a button field to DocType but that field does not show up in report.

How to create a Script Report and add button in the last column of each row?

Regards,

Sorry to bump it.

Is this feature possible in Script Report?

I have the same problem as you, did you have a solution for this?

Sorry I have not been able to find any solution for this yet.

Here is the code I use for a report on Purchase Order:

In your report’s python file:

def execute(filters=None):
	columns = get_columns()
	data = get_data(filters)
	for row in data:
		row["button"] = '<button class="btn btn-sm" onclick="frappe.open_dialog({})">Open</button>'.format("'" + row.name + "'")

	return columns, data

def get_data(filters=None):
	#TODO: consider filters
	return frappe.db.get_list("Purchase Order", fields=["*"])

def get_columns():
	return [
		{
			"label": "ID",
			"fieldname": "name",
			"fieldtype": "Link",
			"options": "Purchase Order",
			"width": 180,
		},
		{
			"label": "Action",
			"fieldname": "button",
			"fieldtype": "Data",
			"width": 180,
		},
	]

and in your report’s javascript file:

frappe.query_reports["<Report Name>"] = {
	"filters": [

	],

	onload: async function (report) {
			frappe.open_dialog = function (po_name) {
			let d = new frappe.ui.Dialog({
				title: 'Enter details',
				fields: [
					{
						label: 'Field name',
						fieldname: 'fieldname',
						fieldtype: 'Data'
					}
				],
				primary_action_label: 'Submit',
				primary_action(values) {
					console.log(values)
					d.hide();
				}
			});
			d.show();
        }

Hope this help.

4 Likes