Add a Dynamic Link field ​

A Link field always points to one DocType. A Dynamic Link field can point to a document of any DocType. A second field, a Link to DocType, says which DocType.

ERPNext uses this pair in many places. For example, an Opportunity can be for a Lead or a Customer. One field selects "Lead" or "Customer", and the next field selects the lead or the customer. You do not need a separate field for each.

Prerequisites ​

  • The System Manager role.

Add the two fields ​

This example adds a reference to any document on a Journal Entry.

  1. Open Customize Form for Journal Entry.
  2. Add the first field:
    • Label: Reference Type
    • Type: Link
    • Options: DocType
    • Note the field name, for example custom_reference_type.
  3. Add the second field below it:
    • Label: Reference Name
    • Type: Dynamic Link
    • Options: custom_reference_type, the field name of the first field.
  4. Select Update.

The user first selects a DocType in Reference Type, for example Sales Order. Reference Name then lists the Sales Orders.

Limit the DocTypes that users can select ​

By default, the first field offers every DocType. To offer only some, filter the first field. Read Add a link field and filter its options. For complex rules, use a client script.