Need to restrict a field according to another value

Dear All,

I want to restrict/filter a filed based on the company name. Linke filed is Contacts and need to filter specific contacts based on its field ‘Company’
and this is my code on depends on block“Company Name”
but its not working. is there anything to be done?

Thank you,

Hi @ramalyb:

Depends on just shows or hide the field on depending on eval condition, is not related to filter.
To achieve your requirements, create a client script like this.

frappe.ui.form.on("yourdoctype", "onload", function(frm) {
    frm.set_query("contact", function() {
        return {
            "filters": {
                "company": "yourcompanyname",

Check this:

BTW, in develop version (and probably soon on stable …), this can be made without code, just using filtering feature on form builder.

Hope this helps.