List all related contracts automatically in the employee page

Hi @ll,
just new here … and maybe not able to search on the correct way (coz of my limited English knowledge)?

I just want to add a tab to the Employee overview. In that tab I want to see all contracts for that employee … and I’m missing the information howto to display all contracts automatically … I already added a link table … and I could choose every contract, one by one and save it … but I would like that all contracts are automatically appears.

Could someone let me know where I can find documentation about how to do that … or maybe give me a short overview how to deal with that issue (it sounds for me like an easy/basic thing … but as mentioned, don’t know for what I have to search for)


Welcome @schmutzfuss !

Option 1. In Employees, tab Profile, section “History in company” you can see something like that.

I don’t know if this fits your requirements, you can customize this child table too. (Doctype name: Employee Internal Work History)

Option 2. Create new one, this way:

Add a doctype for contracts (Contracts) and set it as “Child Table”.
Now in Employees, customize the form:

  • Add a custom field “Tab”
  • Add a new custom field, type “Table”, in Options set: Contracts.

Option 3. Manage Contracts as a separated doctype (no child table), and use “Connections”, so you can navigate between doctypes.

Option 4. Doctype Contracts as a separated Doctype (no child table). Customize Employee form with a child table, and create a client script that populates this table with data from Contracts Doctype.

Hope this helps!

@avc ,
many thanks for your Feedback … one quick question to that …

there is already a “Contract” list available in ERPNext, I just want to use that already existent “thing”, is your option 2 or/and 3 based on the existing contracts or do I create a new kind of “contracts” with that?

I ask … coz until now I tried different ways with linked fields/tables … which are already displaying the contracts, but as mentioned in my first message … not automatically listed, I have to add them all, one by one … instead to just get them all listed … and also that feels like “double” saving … coz the contracts are already in the contract table, why I have to choose and save them again in the “new” self created “employee-contract” table … so I believe I miss some basic understanding about showing/displaying related lists …



Ok, I understand. Yes, Contract doctype can be related with employee as well.
To get tables into forms you need to use “Child tables”. In this case, Contract doctype is not created as child table … so, you can’t “link” it directly.

This is just one way to get what you want. Here we go:

  1. Create doctype named Employee Contract, using this fields info. This doctype is not designed to store data, just for load and show in form. Use “Is Child Table”.

  1. Customize doctype Employees, adding custom fields as showed:

Edit options on Employee Contract and mark “Read Only”

  1. Create a Custom Client Script for Employee Form. Enable it.
frappe.ui.form.on('Employee', {
    refresh(frm) {
        //console.log("Facemos refresh")

function get_contracts(frm, cdt, cdn) {
        'method': 'frappe.client.get_list',
        'args': {
        'doctype': 'Contract',
        'fields': ['name','start_date','end_date', 'is_signed'],
        'filters': [['Contract', 'party_name', '=',]]
    }).done((res) => {
        $.each(res.message, function(_i, e){
           let entry = frm.add_child("employee_contract");
           entry.contract =;
           entry.start_date = e.start_date;
           entry.end_date = e.end_date;
           entry.signed = e.is_signed;

You got it!

Note: You should consider create an app and store on it all the customization. It’s not recommended to directly editing the doctype, because you will lost your changes with upgrading ERPNext. Use customize form instead.

You can improve this method, adding an action button in each row to open contracts from the table. Right now, if you click on contract id, an open dialog will be opened on “read mode” (using secondary button on mouse you can open in other tab …)

Get fun!
Hope this helps.

Hi @avc
at first many thx for your explanations :slight_smile:

I tried to follow your description step by step … (hopefully I didn’t miss anything!) … but at the end the table is not displayed

A few things …

  1. I didn’t have a module called “Contracts everywhere” … so I just created one (no further values)
  2. the whole table is not displayed if I use the “read only” option, without that option the table is displayed, empty … and looks nearly like my version from before (I could choose contracts)
  3. the script docType is Client Script, coz the result was not as expected I created a second one (also enabled) one is Apply to “List”, the other one is Apply to “Form”… not sure which one is the right one.
  4. after Customizing I click on action->reload

Maybe some helpful things which I should now?:

  • do I have to empty a cache somewhere else?
  • how can I check if the script runs proper?

And about your note

You should consider create an app and store on it all the customization

that sounds good/interesting … maybe you can recommend a link to a beginner tutorial/ documentation too?

And a big thank you for the script :smiley: :+1:, alone from reading I got a much better understanding about how to use client scripts



Ok! Little by little :slight_smile:

Don’t worry about that, the module “name” is just a joke :wink:

“Read only” should work as … “read only”, visibility depends on “Hidden” or visibility condition … Use bench clear-cache to assure fresh data. I recommend “Read only” to avoid users modify data from the “fake” table.

Client Script → apply to Form. This kind of scripts runs when you are working into the form, this is our case. “List” scripts work for listviews.

To some debugging, open the console located in the browser developer tools (press F12 in most browsers). After this, open Employee Doctype, and we will see if frappe throws errors. Some comment code in the script (remove comments) contents info that should appears in the console.

It could be helpful too if you share some screenshots of your doctypes, script, etc …

In this videos and docs you will see how to create apps, and link frappe objects to this apps.

You are really welcome. I’m happy to help others, same way other people helps to me. Play with the framework and enjoy learning. Be patient, there are a lot of things to understand!

1 Like

Hi @avc,

“Read only” should work as … “read only”

this was my guess too … but it’s still the thing which is happened:
“Read only” is marked: The whole table will not appear (just nothing, also not the borders or title and so on … just nothing)
“Read only” is not marked: The table appears (still empty)

I guess that I can just not execute your script on the correct way … now I have to understand how the console works … I already activated your console outputs in the script, but I cannot find anything about the script in the console…



Please, show with screenshot how the script is configured, and what you see in the console …

here a screenshot from the script:

and about the console … until now I hvae no clue what to do/how to find anything … I tried the search option and put some words/strings in which are related to the script … but nothing to see … so I just add a screenshot from the console screen … but I’m pretty sure that’s not what you need to see …

where else can I find the needed information?



In Doctype search “Employee”, wich is the doctype where you want to run the script in :slight_smile:

Hope this helps!


deleted many things by editing in this message … sorry … already totally confused … :confused:

anyway … I tried it again … added the script to Employee … and now it works :smiley: :smiley: :smiley:

many many thanks :+1: :slight_smile:


1 Like