How to execute a SQL query from Client Script?

Hello,

I want to execute the following SQL query and load its result in Datatable.

SELECT `tabPurchase Receipt`.name, `tabPurchase Receipt`.supplier_name, `tabPurchase Receipt`.posting_date, `tabPurchase Receipt Item`.item_name, `tabPurchase Receipt Item`.received_qty, `tabPurchase Receipt Item`.rejected_qty, `tabPurchase Receipt Item`.warehouse, `tabPurchase Receipt Item`.purchase_order, `tabPurchase Receipt Item`.batch_no, `tabPurchase Receipt Item`.coil_heat_no, `tabPurchase Receipt Item`.quality_inspection, `tabPurchase Receipt Item`.coil_qty, `tabPurchase Receipt Item`.coil_wt FROM `tabPurchase Receipt`, `tabPurchase Receipt Item` WHERE `tabPurchase Receipt Item`.parent = `tabPurchase Receipt`.name;

How to execute a Custom Query in Client Script?

Actually I want data from two MySQL tables tabPurchase Receipt and tabPurchase Receipt Item

TIA

Yogi Yang

Hi @YogiYang,

Query does not work on the client/custom side.
It’s only worked on below of erpnext version 5.

For reference:



But you can use it via the custom method.
https://frappeframework.com/docs/v14/user/en/guides/app-development/overriding-link-query-by-custom-script#custom-method

Maybe it helps you.

Thank You!