Accessing Chiled Table In Frappe

We are developing a Building Management System using frappe and created a Doc Type called Rental Structure which has a child doc type of Building Floors linked by a “table link”. We then created a new doc-type called Renting Space which is linked to buildings by “link”, what we wanted to do was whenever a building is selected on the Rental Space form we wanted to populate a select field of floors that are a child of that particular building. So that the renting space will have a building and a corresponding floor. Is there any easy way we could script this?

Can u specify field names and behaviour required for field?


This doesn’t sound too difficult. The first big question is whether you need to have it made through a link (which would update every time you change the link), or whether these are one offs generated from the Rental Structure doc. The other question is whether the Renting Space uses the same child doc_type for the table as the Rental Structure (are they both the same Building Floors doctype)?

If the forms are one off, you can write a server-side script that uses the get_mapped_doc command. You could create a button on either form that says “Create Rental Space from Rental Structure” or something like that. I’ve assumed you are using the same Building Floors doctype, so it would look (something) like this:

doc = get_mapped_doc("Rental Structure", self,	{
			"Rental Structure": {
				"doctype": "Renting Space"
			"Building Floors": {
				"doctype": "Building Floors",
				"field_map": {
					"name": "prevdoc_detail_docname",
					"parent": "prevdoc_docname",
					"parenttype": "prevdoc_doctype",
				"postprocess": update_item
			}}, doc,postprocess)

If you need it to update with a link (so that it can update on the fly), I think it gets a bit harder. You’ll need to delete any child docs in the Rental Space’s floors table, then loop through the Rental Structure document’s child table and create new child items for each one, then add them to the new table in Rental Space. I don’t have sample code for that readily available.

Hope this helps