Fetch report Data into custom field of different Doctype

Hello Frappers…!

I have a custom query report “serials”. with columns Serial Number, Item Code, Sales Order, etc.

Then i have a doctype Quality Inspection. What i want is, When the sales order and item code is selected in the Quality inspection form, the field Serial Number Details must fetch all the serial numbers from report like “2509466 to 2509462” OR “2509466” (if only one entry) in the red boxed field. The fetched serial numbers must be relevant to each other as in the report.

Tried too many options in client script based on inputs from gemini ai but no outcome. can some please suggest their inputs ?

Use frappe.db.sql and create a fetch serials python fuction to fetch the related serials

Then call the python whitelisted fuction from client side on trigger of your sales order or item code

Thanks for your response, but i am zero in python!