Export document link as fixture

Hi all,

is there a way to export a new link (showing in the connections of a doctype) that I added via customize form, so that it gets imported on installing my app into another instance?

I am on frappe 14.

Thanks!!

You just have to add the new links in the linked document section of the customize form and click on export customizations.
This should create a json file with the modifications in the module you choose and will be installed in a new instance.

The customization are exported, but on running migrate command, the document links are not created.

1 Like

Hello,

It should be enough to export from ‘custom’.
Select the app to associate, this will create a directory named ‘custom’ in your app’s directory.
image

Also, make sure to check the created directory named ‘custom’.

image

If you are using Git, make sure to apply the changes, and then run a bench migrate .

You can also do it with hook.py
Fixtures are defined in the hooks.py file of your application. To add a fixture, you need to edit this file and add an entry to the fixtures list. For example:

fixtures = ["Custom Field", "Property Setter", "Custom Script", {"dt": "DocType", "filters": [["name", "in", ["Sales Invoice", "Customer"]]]}]

This configuration will export custom fields, property setters, custom scripts, and specific document types “Sales Invoice” and “Customer”.

Exporting Fixtures: To export fixtures, use the console command bench export-fixtures. This command will look for the fixtures configuration in your hooks.py and export the corresponding data to JSON files within your application, in the fixtures directory.

Migrating Fixtures to Another Site: Once exported, these JSON files can be used to migrate data to another site. For this, you need to move your application with the fixtures to another Frappe site and then execute bench migrate. This will import the fixture data into the new site.

Version Control: It is advisable to keep the fixtures files under version control (such as Git) to track changes and facilitate deployment in different environments.

1 Like

Neither of these solutions seem to work, my custom Document Links to the erpnext “Employee” doctype are not pushing to my apps, I have tried using the GUI export (Which did succesfully export custom fields), as well as your hooks.py suggestion, but still, the custom links don’ twork. THis is now on version-15

So the solution I ended up using was to create a setup script and run it before_migrate in hooks.py:

line for hooks.py:

before_migrate = [
	"ir.setup.add_employee_doclinks.ensure_employee_links"
]

contents of apps/ir/ir/setup/add_employee_doclinks.py

import frappe

def ensure_employee_links():
    """Ensure required Document Links exist in the Employee DocType."""
    required_links = [
        {"link_doctype": "Disciplinary Action", "link_fieldname": "accused"},
        {"link_doctype": "Contract of Employment", "link_fieldname": "employee"},
        {"link_doctype": "Incapacity Proceedings", "link_fieldname": "accused"},
        {"link_doctype": "Appeal Against Outcome", "link_fieldname": "employee"}
    ]

    # Fetch existing links
    existing_links = frappe.get_all(
        "DocType Link",
        filters={"parent": "Employee"},
        fields=["link_doctype", "link_fieldname"]
    )

    existing_links_set = {(link["link_doctype"], link["link_fieldname"]) for link in existing_links}

    for link in required_links:
        if (link["link_doctype"], link["link_fieldname"]) not in existing_links_set:
            doc = frappe.get_doc({
                "doctype": "DocType Link",
                "parent": "Employee",
                "parentfield": "links",
                "parenttype": "DocType",
                "link_doctype": link["link_doctype"],
                "link_fieldname": link["link_fieldname"],
                "group": "Industrial Relations"
            })
            doc.insert(ignore_permissions=True)
            frappe.db.commit()
            frappe.msgprint(f"Added missing Document Link: {link['link_doctype']} to Employee")

    print("✅ Employee Document Links verified/updated.")