Thank you @Sandeep_Kakde for your assistance. I appreicaet you taking the time
I will have to see if I can generate the error again to take a screenshot, but it was a prompt and I copied
all the text of the prompt into the message in my previous message.
I have however, tried many other things and have got code now that does not generate any errors.
But I will have to relook at my entrire approach for this project. I will post my existing code, but perhaps
I must start at what I want to achieve…
Custom doctype : BDH
Many fields on BDH. MOst important is
BDH Template ; link to doctype BDH Template. This contains a preconfigured template of parameters
that the user can select, after pre-configuring such a template.
When choosing a BDH Template, it populates the other important item in the BDH doctype which is
a child table called “check_items”
Ultimately I would like to achieve this by writing code for the bdh.js and bdh.py in the folder
…frappe-bench/apps/custom_app/custom_app/customisation/doctype/bdh
On a previous script I did I could call a method in a file api.py in the folder
…/frappe-bench/apps/scrap_item_app/scrap_item_app
But in this case I could not call a method ithe folder
…frappe-bench/apps/custom_app/custom_app/customisation/doctype/bdh
I think one of the big problems is me. I have done a number of client scripts and I am now taking on
some server-side / custom-doctype scripting which is tripping me up.
Let me print my existing code which sort-off-works. It certainly does not have errors. THen you can
get a picture of what I want to do.
Client side code …
frappe.ui.form.on('BDH', {
bdh_template: function(frm) {
if (frm.doc.bdh_template) {
frappe.show_alert("Template", 5);
frappe.call({
method: 'custom_app.api.get_template',
args: {
template_name: frm.doc.bdh_template,
build: frm.doc.name
},
callback: function(r) {
if (!r.exc) {
frm.refresh_field('check_items');
}
}
});
frappe.show_alert("Refresh Table", 5);
frm.refresh();
frm.refresh_field('check_items');
}
},
refresh: function(frm) {
frm.refresh_field('check_items');
}
});
And now the server side code that is in api.py in the folder
…/frappe-bench/custom_app/custom_app
import frappe
@frappe.whitelist()
def get_template(template_name, build):
template = frappe.get_doc("BDH Template", template_name)
bdh_doc = frappe.get_doc("BDH", build)
bdh_doc.check_items = []
for parameter in template.bdh_parameters:
bdh_doc.append("check_items", {
"parameter": parameter.bdh_parameter,
"checked": 0,
"employee": "",
"date": None
})
bdh_doc.save()
My goal is to migrate the client side code to the bdh.js
and to migrate the code in api.py to bdh.py
One big problem with the code that I have put above, is the fact that I pass the parent doc as a
argument. This implies that I have to save the doc first so that it has a proper name to be passed
as an argument. But when you save the doc, the “bdh_template” value in the dtabase table
is saved as NULL ( no selection made yet ) So when the user selects a template, the template name
does not appear in the bdh_template field.
If someone could offer some guidace I would appreciate it