question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Could not find field" When Setting Up A Document Link to a Document with a Child Table

See original GitHub issue

Description of the issue

This is related to #14420 insofar as the reason for writing both bug reports is the same. While that specific issue (AttributeError) was solved, the overarching problem still exists: specifically, you still can’t set up Linked Documents to Link fields in Child Tables using the DocType interface. While this isn’t an easy issue to explain, the issue should be easy to reproduce by attempting to create a connection on a doctype to a document based on a field in the document’s child table.

Say I have a Doctype HostDocType which has a Table Field called the_child_table with the Doctype ChildDocType. This DocType has a Link Field called link_to_subject_docType, which naturally links to a third doctype called SubjectDocType. The hierarchy looks something like this:

HostDocType

the_child_table (ChildDocType)

link_to_subject_docType -> SubjectDocType

I want to set up a “Linked Document” on SubjectDocTypeto relevant HostDocType documents. So I fill out the Linked Documents field in the following manner:

Link DocType: ChildDocType Link FIeldname: link_to_subject_docType Parent DocType: HostDocType Table Fieldname: the_child_table

When I hit save, I will get the following message:

Document Links Row #2: Could not find field the_child_table in SubjectDocType DocType


I’m not sure why its looking for the field in the DocType I’m attempting to place the connection on, but hey, maybe I reversed the fieldnames? So let’s try this:

Link DocType: ChildDocType Link FIeldname: the_child_table Parent DocType: HostDocType Table Fieldname: link_to_subject_docType

Now I get an error that looks correct:

Document Links Row #2: Could not find field the_child_table in ChildDocType DocType

So it is still isn’t possible to set up a Document Link to a document based on the contents of a Child Table.

Context information (for bug reports)

Output of bench version

ERPNext: v13.21.0 (version-13)
Frappe Framework: v13.21.0 (version-13)

Stacktrace / full error message

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 68, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 55, in handle
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 31, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 68, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1213, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/desk/form/save.py", line 21, in savedocs
    doc.save()
  File "apps/frappe/frappe/model/document.py", line 287, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 324, in _save
    self.run_before_save_methods()
  File "apps/frappe/frappe/model/document.py", line 971, in run_before_save_methods
    self.run_method("validate")
  File "apps/frappe/frappe/model/document.py", line 869, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1161, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1144, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 863, in <lambda>
    fn = lambda self, *args, **kwargs: getattr(self, method)(*args, **kwargs)
  File "apps/frappe/frappe/core/doctype/doctype/doctype.py", line 82, in validate
    validate_links_table_fieldnames(self)
  File "apps/frappe/frappe/core/doctype/doctype/doctype.py", line 740, in validate_links_table_fieldnames
    frappe.throw(message, InvalidFieldNameError, _("Invalid Fieldname"))
  File "apps/frappe/frappe/__init__.py", line 444, in throw
    msgprint(msg, raise_exception=exc, title=title, indicator='red', is_minimizable=is_minimizable, wide=wide, as_list=as_list)
  File "apps/frappe/frappe/__init__.py", line 423, in msgprint
    _raise_exception()
  File "apps/frappe/frappe/__init__.py", line 378, in _raise_exception
    raise raise_exception(msg)
frappe.core.doctype.doctype.doctype.InvalidFieldNameError: Document Links Row #2: Could not find field <b>the_child_table</b> in <b>CustomDocType</b> DocType

Additional information

Original bug report was here: #14420

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
barredterracommented, Mar 9, 2022
1reaction
skjbulchercommented, Jul 21, 2022

I can’t tell much without looking at schema of these things and how link is setup. I updated docs with a working example (that’s most common usage too)

https://frappeframework.com/docs/v13/user/en/basics/doctypes/actions-and-links#example-adding-a-new-connection

I think there may be a different problem then. I did notice your instructions, but I assumed that I knew what I was doing. However, after actually following them I got it to work, but the form doesn’t work the way I expected and there may be other issues with this approach.

This is what I mean:

The form has a “Is Child Table” readonly checkbox. It is automatically checked when the Link Doctype field contains the name of a child table DocType, and two additional fields will appear at the same time: Parent DocType and Table Fieldname: image

However, your instructions ignores those fields and has the user select the main DocType under the Link Doctype field, and fill in the Link Fieldname with the child table field. This works, but it gives me pause because I’m not being very specific about what fields I want to connect (is that by intent?). What happens if the child table has a field with the same name as the parent DocType? Would the connection find both links, would it raise an SQL exception…?

If this is correct behavior and it works, the additional fields related to “Child Table” should probably be removed so they don’t confuse people. Otherwise, I think we might need to think about this some more.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Access 2007 "Could not find field" error message
I have an Access database linked to SharePoint 2013. Forms are used to enter the data. Intermittently the users will get the message...
Read more >
link to file based of related field in parent table | Discussions
Hello, I have two tables. Project and Documents Project has a bunch of internal information and the documents are supplied by client /...
Read more >
Adobe Acrobat Pro DC - Common Accessibility Issues
Right-click on one of the fields and then click Properties… The Text Field Properties window will open. 7. Click the General tab.
Read more >
Links in HTML documents - W3C
The destination anchor of a link may be an element within an HTML document. The destination anchor must be given an anchor name...
Read more >
Known issues - Relativity Documentation
When navigating to the Files tab from a Processing Set using the "View File Errors" link, you can not place additional conditions on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found