Custom script with doctype : failed to get method


Busy with my next custom app, this time with a doctype.

Procedure I followed

Developer mode is active

bench new-app custom_app
bench --site site2.local install-app custom_app

new app is listed in …/sites/apps.txt

On the Desk
goto Module Def List and create new module linked to app “custom_app”

create new doctype “BDH” linked to module “customisation”
on server, in folder … custom_app/customisation/doctype/bdh in the file, I entered my
python code… (using file that was auto created)

import frappe
from frappe.model.document import Document

class BDH(Document):

def populate_check_items(bdh_template, bdh):

   ....... rest of pythin code...........

And in my client script, I call the method like this …{
       method:  ' custom_app.customisation.doctype.bdh.populate_check_items',

after creating my PY-file

bench --site site2.local migrate
bench restart

I also changed permissions on …

chmod 777

And the error I get is … (when I select the related field on the BDH-document )

Failed to get method for command
custom_app.customisation.doctype.bdh.populate_check_items  with module
custom_app.customisation.doctype.bdh  has no attribute

Would apprecaite some assistance with this, please
Thank you

Can you share the screenshot of the error.
Also in you Client Script I see space is there before custom_app, can you remove it and check again.

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 in the folder

On a previous script I did I could call a method in a file in the folder

But in this case I could not call a method ithe folder

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);
                method: 'custom_app.api.get_template',
                args: {
                    template_name: frm.doc.bdh_template,
                callback: function(r) {
                    if (!r.exc) {
            frappe.show_alert("Refresh Table", 5);
    refresh: function(frm) {

And now the server side code that is in in the folder

import frappe

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

My goal is to migrate the client side code to the bdh.js
and to migrate the code in to

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

It should be like this


Thank you @mohitchechani for taking the time to assist.

Update …

Thank you for the assistance. I have been trying many things and in the end I decided to go for broke and put everything
on the server side. i.e. not use client side scripting.

I put my JS in my …/doctype/bdh/bdh.js file and my PY code in …/doctype/bdh/ file.

This is my code that seems to be working …

frappe.ui.form.on('BDH', {
//  refresh: function(frm) {

//  }
    bdh_template: function(frm) {
        if (frm.doc.bdh_template) {
                method: "get_template",
                doc: frm.doc,
                callback: function() {

PY code

import frappe
from frappe.model.document import Document

def get_template_details(template):
    if not template:
        return []
    return frappe.get_all(
        "BDH Template Parameter Item",
        filters={"parenttype": "BDH Template", "parentfield": "bdh_parameters"},

class BDH(Document):

    def validate(self):

    def get_template(self):
#       frappe.msgprint("Get Template")

        self.set("check_items", [])
        parameters = get_template_details(self.bdh_template)
        for d in parameters:
            child = self.append("check_items", {"parameter": d.bdh_parameter})

Thank you