{% if doctype and docname and not thread %} {% set thread_info = frappe.get_all("Discussion Thread", {"reference_doctype": doctype, "reference_docname": docname}, ["name"]) %} {% if thread_info | length %} {% set thread = thread_info[0].name %} {% endif %} {% endif %} {% if thread %} {% set messages = frappe.get_all("Discussion Message", {"thread": thread}, ["name", "message", "owner", "creation"], order_by="creation") %} {% endif %} {% if doctype %}