Frappe Client get linked docs

Looking for a way to get linked docs from Frappe Client:

def api_get_linked_doc(doctype, name, filters, limit_start, limit_page_length):
    params = {"doctype": doctype,
              "name": name,
              "filters": filters,
              "limit_start": limit_start,
              "limit_page_length": limit_page_length
              }
    docs = client.get_api("frappe.desk.form.linked_with.get_linked_docs", params)
    print(docs)

But all it seems to return is ‘None’ but I can see the linked documents in the GUI. Sales Order to Sales Invoice in this case.

None is returned because the get_linked_docs method needs different parameters than what you are passing it.
params = {doctype, docname, linkinfo, for_doctype}

Doctype and docname you can easily get. Linkinfo can be fetched from get_linked_doctypes method of linked_with.py module.

from frappe.desk.form.linked_with import get_linked_docs, get_linked_doctypes

linkinfo = get_linked_doctypes(doctype)
docs = get_linked_docs(doctype, docname, linkinfo)
print(docs)

4 Likes