Help on error fetching data from another doctype

Hi,
I’ve pasted the code I found here and changed adapted to my doctypes and fields. But when I change the selected box I got the following error

My code is

frappe.ui.form.on("Qualification Entry", "qualification",
    function(frm) {
        frappe.call({
            "method": "frappe.client.get",
            args: {
                doctype: "Qualification",
                name: frm.doc.certificate_required
            },
            callback: function (data) {
                frappe.model.set_value(frm.doctype,
                    frm.docname, "certificate_required",
                    data.message.certificate_required
                    )
            }
        })
    });

I don’t understand what’s not found.
Any suggest?

@emakis Can you explain what you want to get done here.

Regards,
Deep Trivedi

So, interesting thing with frappe.client.get.

If you don’t pass in name , or name is None, AND you don’t pass in a filters arg, the method looks for a doctype of type Single - hence the message “Qualification Qualification not found.”

You must ensure that you are passing a name arg into your call to frappe.client.get to get a non-single doctype. You could bind the method to “certificate_required” to ensure that there is a value to pass in, and I would also validate that before the call with something like this…

frappe.ui.form.on("Qualification Entry", "qualification", function(frm) {
// consider using "certificate_required" above instead of "qualification" - 
// this helps ensure you get a value passed in. You also should validate with
// comparison to null -> != instead of !== to allow js to do type conversions
      if(frm.doc.certificate_required != null) { 
        frappe.call({
            "method": "frappe.client.get",
            args: {
                doctype: "Qualification",
                name: frm.doc.certificate_required
            },
            callback: function (data) {
                frappe.model.set_value(frm.doctype,
                    frm.docname, "certificate_required",
                    data.message.certificate_required
                    )
            }
        })
      } else {
        // logic here to do something (maybe) if there is no value in your
       // "certificate_required" field. 
      }
    });

ty @alec_ruizramon1 for your response.
I need the call fired when the user makes a selection in the linked field qualification. That’s why I set "qualification" in first line. If I change it to certificate_required then the event fires on check / uncheck of certificate_required field which is not the proper action.
As far the certificate_required field, this is actually a hidden field and its status (checked / unchecked) depends on the returning value of the Qualification.certificate_required field (the other docType named Qualification, field certificate_required)

It seems to me that I set the parameters correct but I am getting that strange error :confused:

If certificate_required is a check, you can’t pass it in as the name of the Qualification document you’re trying to get!

oops!
And what’s the solution on that? How can I inform the user if a certain Qualification requires certificate or not?

Try passing frm.doc.qualification instead of frm.doc.certificate_required in the name parameter.

args: {
   doctype: "Qualification",
   name: frm.doc.certificate_required
}
2 Likes

you can take referance from this :- https://www.youtube.com/watch?v=f4gPxUay7v0 go on 2:24, fetch other doctypes field without any coding