I have a data model (navigation_menu_items) that I have setup with parent and children to allow for nested navigation_menu_items. Currently this allows for a user to set a navigation_menu_item’s parent to itself. I’m trying to prevent this by setting up a Flow. My current flow is partially working, where it does successfully prevent a user from sending the parent to itself, but for some reason valid updates no longer will save. Like if I change the label or sent a valid parent, it will allow me to click the save button, but the data doesn’t actually change.
Here is my setup:
Trigger: Event Hook
Type: Filter (Blocking)
Scope: items.create, items.update
Collection: navigation_menu_items
Response Body: All Data
Operation: Run Scirpt
Code:
module.exports = async function (data) {
const payload = data.$trigger.payload || {};
const keys = data.$trigger.keys ||;
const currentId = Array.isArray(keys) ? keys[0] : null;
const parent = payload.parent;
// If parent equals the current ID (as string), throw an error
if (parent && currentId && String(parent) === String(currentId)) {
throw new Error(‘A menu item cannot have itself as a parent.’);
}
return data;
};
Any help would be greatly appreciated!
