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 eval:doc.company==“Company Name”
but its not working. is there anything to be done?

Thank you,
Ramaly

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:
https://frappeframework.com/docs/user/en/guides/app-development/overriding-link-query-by-custom-script

BTW, in develop version (and probably soon on stable …), this can be made without code, just using filtering feature on form builder.
https://docs.erpnext.com/docs/user/manual/en/creating-custom-link-field

Hope this helps.