Hello,
I am stuck in the getting the object of Dynamic Link.
I have one record in dynamic link table. Its relation of customer and its address.
See,
Now, I want to get the object of this doctype.
So, I just write following code to get the object:
test = frappe.get_doc({
“doctype”:“Dynamic Link”,
“link_name”: shipper,
“parenttype”:‘Address’
})
in shipper, I receive the chandresh 007 value.
with the help of this code, I am getting the object of my dynamic link doctype.
See,
frappe.core.doctype.dynamic_link.dynamic_link.DynamicLink object at 0x7f0318eea310
Now, if i am access the other fields of dynamic link like test.parent, then it give me None value insted of “My Address - Billing”.
So, Can you guide me to solve this problem?
Thank You.
What is the output of test?
get_doc
syntax as follows,
frappe.get_doc("DocType", "docname")
e.g.
customer_doc = frappe.get_doc("Customer", "CUST-00001")
I am getting the object of dynamic link in to the test variable.
As your SQL query says link_name
is chandresh 007
you used link_name
as shipper
in get_doc
recheck it and try again.
If there is no document present with link_name = shipper still get_doc gives object of the given type and name.
In shipper, I got the value as chandresh 007 which is the name of my customer.
check the result of test.as_dict()
it shows you details of fetched object.
you can also use
frappe.db.get_values("DocType", "docname"/filters, [list of fields])
The output of test.as_dict() is:
{u’link_title’: None, u’link_doctype’: None, u’modified_by’: None, u’name’: None, u’parent’: None, u’creation’: None, u’modified’: None, u’doctype’: ‘Dynamic Link’, u’idx’: 0, u’parenttype’: ‘Address’, u’link_name’: u’chandresh 007’, u’owner’: None, u’docstatus’: 0, u’parentfield’: None}
Chandresh_Thakkar:
‘name’: None
There is no document present with given data.
Here get_doc
gives you new object using provided data.
So, Tell me that how can i get the object of dynamic link with link_name. Because i have only the value of customer, which is related to the dynamic link with address.
If you have name of document then you can use,
frappe.get_doc("Doctype", "docname")
otherwise, you can use - get_values ()
,
frappe.db.get_values("Dynamic Link", {
"link_name": shipper,
"parenttype":'Address'
}, "*", as_dict=True)
3 Likes