Hey fellow Knack users!
If you’ve ever needed to find where in a Knack application email rules are set up, you know it can be a daunting task. Especially in larger applications, searching through every form one-by-one is not just tedious, but also a massive time drain. I was unable to find a solution online and decided to write a quick script.
Introducing a Handy Script to Save Hours
Rather than searching manually, I produced this code to get a swift list of all locations where email rules are defined. Here’s the code:
const buildUrl = (appName, appSlug, sceneKey, viewId) => {
return `https://builder.knack.com/${appName}/${appSlug}/${sceneKey}/${viewId}`;
};
const hasEmails = view => Boolean(view.attributes?.rules?.emails?.length);
const getEmailUrls = models => {
const appAttributes = Knack.app.attributes;
const { name: appName, slug: appSlug } = appAttributes;
return models.reduce((acc, model) => {
const foundView = model.views.models.find(hasEmails);
if (foundView) {
const url = buildUrl(appName, appSlug, foundView.attributes.scene.key, foundView.id);
acc.push(url);
}
return acc;
}, []);
};
const emails = getEmailUrls(Knack.scenes.models);
console.table(emails);
How to Use This Code:
- Navigate to your Knack application’s live site (no need to be logged in).
- Open the browser’s developer tools and select the console tab.
- Paste the code above into the console and hit enter on your keyboard.
- The result will display as a table. Depending on your display settings, you might need to adjust the width of the table to view the full URLs.
Using this, I was able to quickly track down the specific email I was searching for without the manual hassle.
I hope this helps some of you out there looking for a quicker solution!
Cheers and happy coding!