I have a client script for the Batch DocType which on pressing a custom button on the form, gets values from the DocType and prints them to a label printer. Works well and quite happy.
However, I am struggling to find a way to use the same approach on Purchase Receipt DocType, to get information from the Purchase Receipt Items child table, and send them to the client script to print.
I have looked at the docs but it isn’t clear, I’ve tried following some YT videos on child tables but they don’t seem to work in v14.
Can anyone tell me how this can be achieved, or a good source of info on how to achieve this?
Thanks, I have very little Python knowledge at the moment but hopefully find something. Is it easy enough to transfer the data from the server script to client script?
Welcome, you dont need to write any python code, i just mentioned client.py so that you can get more api options examples for now you can use the script i gave to fetch any doctype with its child tables data, JS will receive data inside r.message
@PyJumper I have got the code working but not sure of how to filter it and keep it to the info associated to the parent DocType only. It’s a bit beyond my current understanding, but I’ll keep trying.
In the meantine I have modified the following code from a YT video by D-codE, to try and display the information I want to get from the child table, but is does not seem to work.
frappe.ui.form.on('Purchase Receipt', "refresh", function(frm) {
frm.add_custom_button(__("Print Label"), function(){
// When this button is clicked, do this
frappe.msgprint(__("Print labels from '{0}'",
[frm.doc.naming_series]))
for (let row of from.doc.purchase_receipt_item) {
frappe.msgprint(__("{0}. Item '{1}' Labels:'{2}'",
[row.idx,row.item_code,row.qty]))
}
}
)});
It displays a popup as expected but only with the parent DocType info, the Child table info doesn’t appear.
Got it, I had for (let row of from.doc.purchase_receipt_item) when it should have been for (let row of frm.doc.items)
So one misspelling for frm and I needed to name the link field in the Parent Doc, not the Child table name.