V5 get_doc and get_value cannot pull data from documents out of current view

Using Custom Scripts, I have not been able to pull documents or values of fields using frappe.model.get_doc and frappe.model.get_value for documents that is currently on the existing page that the browser is viewing. E.g. If It is viewing a Project with ID 0001 I can only use get_doc / get_value to pull the Project with ID 0001.

If I try to pull Project with ID 0002 it returns Null.

Is this no longer available in v5? - perhaps due to some security patch. If so, are there any alternatives?

Just some updates:

  • frappe.model.get_value and frappe.model.get_doc actually are able to pull data that is cached. I.e. if I had previously viewed those documents in the current session the data will be retrievable

Should use

frappe.model.with_doc(doctype, name, function() { 
  frappe.model.get_doc(...)
}):

Yes that works. Thanks.

May I also ask, when using with_doc, and if we use set_value, what function do we call to commit the set_value to the database? I have the following custom script running within the Project doctype and I want to save data to the Task doctype. The following does not work btw:

frappe.model.with_doc("Task", cur_frm.get_field("tasks").grid.grid_rows[row].doc.task_id, function(task) { 

    var row_task_type = cur_frm.get_field("tasks").grid.grid_rows[row].doc.task_type;

    frappe.model.set_value("Task", task, "task_type", row_task_type);

    msgprint("Result: " + frappe.model.get_children("Task", task, "task_type"));
});

This is not easy via custom script. Add another column and fix it via the server side like how other properties are set.