Get_doc by javascript

Im trying to do a get_doc by javascript but the return is “null”

let doc_task = frappe.model.get_doc("Purchase Invoice", "NF-COMPRA-00046");
console.log(doc_task)
1 Like

try console.log(doc_task.as_dict) or console.log(doc_task.name)

Uncaught (in promise) TypeError: Cannot read property ‘name’ of null
Awkward… I paste the code in another custom script(Purchase Invoice doctype), and that worked…

Is impossible do get_doc of Task form?

On Task form, when I do frappe.get_doc(cdt, cdn) that works
But when I pass string args, this is not working:
frappe.get_doc("Task", "TASK00145")

task doc

Just doc_frame works

frappe.ui.form.on("Task", "refresh", function(frm, cdt, cdn){
	doc_manual = frappe.get_doc("Task", "TASK00226");
	doc_frame = frappe.get_doc(cdt, cdn);
	console.log(doc_manual);
	console.log(doc_frame);
});

Any help? I think that’s a bug

Sorry, I haven’t received notification. I’ll check and update you

Thanks a lot!

I think you can use frappe.call. try it.

 frappe.call({
             method: "frappe.client.get",
             args: {
                 doctype: "Task",
                 name: "TASK00226",
             },
             callback(r) {
                 if(r.message) {
                     var doc_task = r.message;
                 }
             }
         });
1 Like

I don’t think frappe.get_doc is implemented the way it should in JS. Maybe there is a better option.

1 Like

Nothing happened

I’ve checked this one but I have TASK00001 and it works

I have
ERPNext: v8.11.3 (master)
Frappe Framework: v8.10.6 (master)

why do you need get_doc? you can use frm.any_key_name

This works just in the same task doctype.
Create another task and try get the TASK00001 in there.

I’m not in task doctype. I’ll do this in Timesheet form, the "Task, refresh" is just for an example to understand that cdt and cdn works, but the strings args it’s not working.

yes, I see. so I think you should check other way for receiving data from (example) TASK00001

Yes I am, I did a console log on my variable.
Create another task and try get task00001 on your new task and see what happens, just cdt and cdn will works

yes, because cdt it’s current doctype, cdn it’s current docname

yes, I’ve checked and seen that it doesn’t work

Yes! but cdn and cdn is just a string, like “Task”, “TASK00001”
Cause idk why the string it’s not working, cause you’re passing string, doesn’t matter if is the current doctype or not, the doctype exists and this has to do get_doc in the same way!
Did you agree with me? Or I’m wrong?!

I added show console log. pls check again

frappe.call({
        method: "frappe.client.get",
        args: {
            doctype: "Task",
            name: "TASK00226",
        },
        callback(r) {
            if(r.message) {
                var task = r.message;
                console.log(task);
            }
        }
    });
3 Likes