Add button to script report

hi all
any help guys on how to add a button to a script report with onclick event fires function in py file.

regards

1 Like

Any help guys?

Hii
Can you be more specific about your requirement ?
Do you require the button in the menu ? or in report detail ?

Thank you :slight_smile:

Hi @fahimalizain
In report detail which i click on it and fire up a py method with the row idx as parameter.

Regards

In a Data report column, add your button just like in this post: Button in Script Report
While adding though, you have to give the javascript function name as a part of the string

"<button type ='button' data-arg='%s' onclick='custom_func()'>Receive</button>" % (arg)

now add your custom_func with your parameter in your custom apps /public/js folder, specify in build.json,
and finally do app_include_js to that minified js file.

Now, this custom_func should make a frappe.call to your python method.

EDIT: argument is an issue

"""<button type ='button' data='%s' onClick='test_method(this.getAttribute("data"))'>Receive</button>""" % (d.get('party'))

This works :smiley:

1 Like

can you please @fahimalizain give me an exemple how am using query report

regards

hii…
sorry for the late reply…

Where do you want to add this ? to query report or script report ?

Query report thank you @fahimalizain

Not sure if this is possible with query report… But I’m 100% that it can be done via script report.

Can you share with with script report

check: https://frappe.github.io/frappe/user/en/guides/reports-and-printing/how-to-make-script-reports.html

Hii
Check this, this is Open Production Orders report

SELECT
  `tabProduction Order`.name as "Production Order:Link/Production Order:200",
  `tabProduction Order`.creation as "Date:Date:120",
  `tabProduction Order`.production_item as "Item:Link/Item:150",
  `tabProduction Order`.qty as "To Produce:Int:100",
  `tabProduction Order`.produced_qty as "Produced:Int:100",
  `tabProduction Order`.company as "Company:Link/Company:",
  CONCAT('<button type=''button'' data=''', `tabProduction Order`.name ,''' onClick=''consoleerp_hi(this.getAttribute("data"))''>Button</button>') as "Button:Data:100" 
FROM
  `tabProduction Order`
WHERE
  `tabProduction Order`.docstatus=1
  AND ifnull(`tabProduction Order`.produced_qty,0) < `tabProduction Order`.qty
  AND NOT EXISTS (SELECT name from `tabStock Entry` where production_order =`tabProduction Order`.name) 

and add this following js function via app_include_js

function consoleerp_hi(data) {
	alert(data)
}

Tested and the alert is shown :slight_smile:
You can tweak this according to your needs.

EDIT: Screenshot

Thank you

5 Likes

Thank you so much