ERPNext Foundation ERPNext Cloud Chat Blog Discuss Frappé* Donate

Override the Link field based on Select Field


#1

I have a link field whose value i want is to change on another select field.
Doctype A --> Doctype 1
Doctype B --> Doctype 2

I am having a field option and category in Doctype B which is link field for Doctype A

	 frm.set_query("option", "doctype B", function() {
        return {
            filters: {
                "category": cur_frm.doc.category
            }
        }
    });
    cur_frm.refresh_field('option');

But its not working.
What I want is on changing field value of category in Doc B, only the list of those (from Doc A) appears in link field having category same as selected in Doc B. I had already created caetgory field in Doc A also


#2

Check this, you’ll get an idea.


#3

thanks, solved using this:

frappe.ui.form.on("Draft", {  "category": function(frm) { 
frm.fields_dict['option'].get_query = function(doc) {
	return {
		filters: { "category": cur_frm.doc.category }
	       }
	}
	cur_frm.refresh_field('option');
}
});

BTW I don’t guess refresh field is helping me out anyhow :thinking: . Correct me if I’m wrong :slight_smile:


#4

You may need to put it in setup event which fired only one time when form created.

Edit:
Yes, refresh field is not needed here.