Filter doctype List and Table fields

Hello, it would be nice to be able to add a filter to the Link and Table doctype fields.

For instance, I have “Drawers” that contain “Folders”. When I select a Drawer I would like only Folder that are in the drawer to be listed.

I know this can be done using the doctype.js, but a built in way would solve many issues.

Maybe extending the “Options” field?

I would be happy to work on this if someone can point me to a starting place.

Thank you,

Hi,

You shall create a custom script for the doctype like this directly from the web interface (Setup → Custom Script):

frappe.ui.form.on("Item", "onload", function(frm) {
	cur_frm.set_query("folder", function() {
		return {
			"filters": {
				"folder": frm.doc.drawers
			}
		};
	});
});

In the lower part of the page you will find some examples. You can also search for custom script on this forum for examples.

1 Like

@sorin.negulescu Thank you. However, this is more a feature request than a question of how too.

It would be nice if a filter feature was “built-in” to the doctype fields.

Thank you,

Can we set multiple filters on same field ? If yes, then how can we do that ?

Thanks,
Hardik Gadesha

Sorry. I don’t know how to do that.

@sorin.negulescu

i have tried this. i want to filter doctypes based on status field. Whose status will be “Open” or In “Feeding”

return {
“filters”: {
“status”: “Open”,
“status”: “In Feeding”,
“batch_no”: frm.doc.batch_no
}
};

Hmm, I see. I actually don’t know what is the correct syntax for that. I don’t think that doubling the “status” key would work.
Someone who knows how filters are implemented can help you with that.

It might be something like this:

return {
            "filters": {
                 "status": ["Open", "In Feeding"],
                 "batch_no": frm.doc.batch_no
            }
        };

But I am not sure.

Okay.

Thanks @sorin.negulescu For your efforts :slight_smile: