frappe / frappe

Low code web framework for real world applications, in Python and Javascript
https://frappeframework.com
MIT License
7.02k stars 3.35k forks source link

ClientScript: Creating new instances with frappe.get_doc() always returns null #14212

Closed zongo811 closed 3 years ago

zongo811 commented 3 years ago

Description of the issue

I'm trying to code a function in ClientScript that copies a record from a DocType called "ProjectEmployee". The first step would be to create an empty instance of ProjectEmployee. For that I tried using frappe.get_doc() and frappe.new_doc(), but to no avail.

Context information (for bug reports)

Output of bench version

erpnext 13.10.2
frappe 13.10.0

Steps to reproduce the issue

  1. Create a ClientScript for a DocType
  2. Code something like this, replace DocType-name "ProjectEmployee" with your DocType-name.
    let newProjectEmployee_1 = frappe.get_doc("ProjectEmployee");
    let newProjectEmployee_2 = frappe.get_doc({
        doctype: "ProjectEmployee",
        title: "New ProjectEmployee"
    });
    let newProjectEmployee_3 = await frappe.new_doc("ProjectEmployee");
    debugger;
  3. Enable Development Tools in your Browser, execute script and watch behaviour in Debugger and Browser

Observed result

newProjectEmployee_1 and newProjectEmployee_2 are null

frappe.new_doc(...) opened the quick entry dialog for the DocType

Expected result

newProjectEmployee_1 and newProjectEmployee_2 contain references to new instances of a DocType-record. frappe.get_doc(...) should behave as documentations states (https://frappeframework.com/docs/user/en/api/document#frappeget_doc): _frappe.getdoc(dict) Returns a new Document object in memory which does not exist yet in the database.

frappe.new_doc(...) should create a reference to a new instance instead of opening the quick entry dialog for the DocType. Even this is a handy feature to have, behaviour should be customizable by a optional parameter, e.g.:

frappe.new_doc(doctype="DocTypeName", showDialog=true)

The documentation of the Javascript API does not cover any of this, documentation should be extended.

Stacktrace / full error message

None

Additional information

OS version / distribution: Debian Buster, Browser: Firefox 78.12.0esr (64-bit) under Debian

surajshetty3416 commented 3 years ago

frappe.get_doc only returns doc if it is loaded in the client-side locals. You can use frappe.db.get_doc instead.