Try ERPNext Buy Support Partners Foundation

Help with field filter in JS

Hi, could someone please cast their eye over this script to see what I’m doing wrong?

I have been through some other posts and have tried to copy journal_entry.js, but this script doesn’t appear to get run at all. I have tried restarting the dev server (bench start), clearing cache, refreshing my browser…

Background: Web Page Section is a parent doctype with Table field items that points to child doctype Web Page Section Item, which has fields content_doctype (Select) and content_document (Dynamic Link pointing to content_doctype).
I’m trying to add a dynamic filter to the Dynamic Link. The script is in a file called web_page_section.js in the directory with the same name along with the web_page_section.py file that does get run.

frappe.ui.form.on("Web Page Section", {
	onload: function(frm) {
		var me = this;
		me.frm.set_query("content_document", "items", function(doc, cdt, cdn) {
			const item = locals[cdt][cdn];
			console.log("This is the item name: " + item.name + cdt + cdn);

			if (item.content_doctype==="Blog Post") {
				return { filters: {'published': 1} };
			} else if (item.content_doctype==="Item") {
				return { filters: {'show_in_website': 1} };
			} else {
				return {};
			}
		});
	}
});

(and before anyone points it out, I know the functionality is vaguely similar to frappe’s Web Page page builder)
TIA!

Please refer this example on applying filters -

Include this script in build.json, if its part of your custom app.

Thanks, I’ve been through the documentation, I can’t see the problem

Thanks, I found the following, but aren’t they for public scripts rather than logged in desk users?

./apps/frappe/frappe/public/build.json
./apps/erpnext/erpnext/public/build.json

No idea why it wasn’t running before, but the final working script as of v13 is:

frappe.ui.form.on("Web Page Section", {
        onload: function(frm) {
                frm.set_query("content_document", "items", function(doc, cdt, cdn) {
                        const item = locals[cdt][cdn];

                        if (item.content_doctype==="Blog Post") {
                                return { filters: {'published': 1} };
                        } else if (item.content_doctype==="Item") {
                                return { filters: {'show_in_website': 1} };
                        } else {
                                return {};
                        }
                });
        }
});