After Creating Virtual Doctype in frappe ERPnext I get this Error

HI
after following these steps in documentation (Virtual DocTypes) for creating virtual doctype it shows the following error without adding any custom code

AttributeError: 'CustomerSubEntry' object has no attribute '_table_fieldnames'

console log shows this error:


Traceback (most recent call last):

  File "apps/frappe/frappe/app.py", line 69, in application

    response = frappe.api.handle()

  File "apps/frappe/frappe/api.py", line 54, in handle

    return frappe.handler.handle()

  File "apps/frappe/frappe/handler.py", line 45, in handle

    data = execute_cmd(cmd)

  File "apps/frappe/frappe/handler.py", line 83, in execute_cmd

    return frappe.call(method, **frappe.form_dict)

  File "apps/frappe/frappe/__init__.py", line 1581, in call

    return fn(*args, **newargs)

  File "apps/frappe/frappe/desk/form/load.py", line 38, in getdoc

    run_onload(doc)

  File "apps/frappe/frappe/desk/form/load.py", line 369, in run_onload

    doc.set("__onload", frappe._dict())

  File "apps/frappe/frappe/model/base_document.py", line 203, in set

    if not as_value and key in self._table_fieldnames:

AttributeError: 'CustomerSubEntry' object has no attribute '_table_fieldnames'

is there any way to fix this?

thank you soo much in advance

1 Like

Hi @maliknaqibullah
when you create new Virtual DocType you should modify function file .py (for the same virtual DocType ) to get and view data from your API
For example: in your file .py for Virtual DocType you have function

	@staticmethod
	def get_list(args):
        pass

this function should return array contains object and the object contains the name that you want show in List View .
you can create function to get users and return all user in the form of an array containing dictionary like this

	@staticmethod
	def get_list(args):
		return get_all_users()
    def get_all_users():
		api = requests.request("GET","https://Your_API")
        return api.json()

After that, you must give the information that should be displayed when the user moves to one of the users Through the function

        def load_from_db(self):
            pass

Which you will also find in the same .py file for Virtual DocType
This function will display the user selected from the list view

	def load_from_db(self):
		d = get_info_user(self.name)
		super(Document, self).__init__(d)
    def get_info_user(user):
	    api = requests.request("GET",f"https://Your_API/{user}")
	    return api.json()

Notice that I pass the name to the function, which gives me this user’s information