Tree View issue

Hello Guys,
I want to make a tree view for custom doctype and i am having difficulty in creating a tree view. Can anyone tell me steps to make a tree view and also the most imp thing that there is a option in doctype list “is Tree” in version 1 2, what is the purpose of that option ??
Any help will be highly appreciatable

1 Like

Hi Owais,
pls try below steps
Step 1: You just create your file tree path for example item group(item_group_tree.js) like,
frappe.provide(“frappe.treeview_settings”);
frappe.treeview_settings[‘Item Group’] = {

    onload: function(treeview){

   }

};
Step 2: Next you import the default tree format path
from frappe.utils.nestedset import NestedSet.

Then your doctype show tree format

Checking Is Tree will implement tree view for that doctype. The system will add lft and rgt fields to the doctype for building the tree along with is_group and parent doctype field.

i created 2 parent enteries in my doctype but tree view is showing only one entry and the other one is not showing… and can you tell me how can i add filter for tree view ??

can you tell me how can i add filter for tree view ??

Pls send the screenshot and tell your doctype name…and then you must create field parent_doctype(ex:parent_item_group).

@Jecintha thanx for you reply… right now i am facing an issue when i click add child in tree view option it shows error
KeyError: ‘sales_agency_name’
my method for add child is:
@frappe.whitelist()
def add_node():
from frappe.desk.treeview import make_tree_args
args = frappe.form_dict
args = make_tree_args(**args)
frappe.get_doc(args).insert()

print args and send the screen shot …
Pls tell me Your doctype name sales agency?

Tree view format must you create those fields doctype_name and parent_doctype,
Your doctype name like sales agency so you ll create sales_agency_name and parent_sales_agency

you called frappe method so this method try to set add child defaults fields but you dont have correct field name then only shown this error pls crt filed name

my doctype name helpdesk category so i created above fields and attached screenshot for your reference if you face again this error pls let me know

It still giving the same error

Pls send doctype screenshot…

sorry it was working it needs cache clear but another hurdle came…

  1. what’s I supposed to do here is: "When “Group_Node” is ticked on the dialogue, it will create the entry with “Is_grouped” checked but no ‘Parent’ set, (so it will be parked under the root)…
  2. When “Group_Node” is not ticked, then it will create the entry with “is_group” unchecked but parent set tot he current parent (Folder Name)
    but its giving error on both when i check group_node tick and when it is unchecked… especially on parent node
    “Could not find Parent Mobile Sales Team: Mobile Sales Team”
    this is the error

Step:1 Here All helpdesk category Group node not ticked becoz this is root and parent not set


Step:2 i)select all helpdesk category root and click add child
ii)Enter the new entry and Group node is ticked then click on create new button
iii)to open you created new entry it’s automatically set parent name as ‘root name’ via import nestedset file (here breakdown req is new entry and this parent name is all helpdesk category)
iv)Select new entry and click on add child to create new entry but group node not tick this is a child entry and then click create new button. To open now created new entry parent name set as step (ii).(here engineering utilities is child entry and parent name is breakdown request).
Step:3 when Group node is ticked automatically parent name set as root name for all.
Step:4 It’s all happened you have field must parent_doctype(my field name parent_helpedesk_category i.e helpdesk category is doctype name) and you must assigned in py file like nsm_parent_field = “parent_helpdesk_category”

I have already assigned parent_doctype field and also in py file and also inherited NestedSet class but still it happening… In this screenshot i have click to add child and when i fill these values with group_node ticked and also not ticked, it prompt error
“Could not find Parent Mobile Sales Team: Mobile Sales Team”

You facing could not find parent error then how it’s created sales and mobile sales parent entries …this error show only click create new button ,attach the console error

Traceback (most recent call last):
File “/home/frappe/frappe-bench/apps/frappe/frappe/app.py”, line 60, in application
response = frappe.api.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/api.py”, line 55, in handle
return frappe.handler.handle()
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 22, in handle
data = execute_cmd(cmd)
File “/home/frappe/frappe-bench/apps/frappe/frappe/handler.py”, line 61, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 1042, in call
return fn(*args, **newargs)
File “/home/frappe/frappe-bench/apps/erpnext/erpnext/crm/doctype/mobile_sales_team/mobile_sales_team.py”, line 27, in add_node
frappe.get_doc(args).insert()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 223, in insert
self._validate_links()
File “/home/frappe/frappe-bench/apps/frappe/frappe/model/document.py”, line 756, in _validate_links
frappe.LinkValidationError)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 364, in throw
msgprint(msg, raise_exception=exc, title=title, indicator=‘red’)
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 350, in msgprint
_raise_exception()
File “/home/frappe/frappe-bench/apps/frappe/frappe/init.py”, line 316, in _raise_exception
raise raise_exception(msg)
frappe.exceptions.LinkValidationError: Could not find Parent Mobile Sales Team: Mobile Sales Team

pls tell me what you try in add_node method i think this is the pblm
bench/apps/erpnext/erpnext/crm/doctype/mobile_sales_team/mobile_sales_team.py”, line 27, in add_node
frappe.get_doc(args).insert()

Comment the above line and try again show the same error?

Nothing happened and it didn’t insert that entry…

this is the method:
@frappe.whitelist()
def add_node():
from frappe.desk.treeview import make_tree_args
args = frappe.form_dict
args = make_tree_args(**args)
frappe.get_doc(args).insert()