Is there a way to create a catch-all function that runs for every action? I’ve looked through the docs but couldn’t find anything. Any ideas or workarounds? Thanks for your help!
I’ve encountered a similar issue in my Zapier projects. While the perform function is useful, it might not be the best fit for pre-trigger field operations. Instead, consider using a shared function approach. You could define a single function and reference it for each trigger key:
This method maintains the specific trigger key structure Zapier expects while reducing code duplication. It’s been quite effective in my experience, offering both clarity and efficiency.
I’ve found a neat workaround for this situation that’s been really useful in my Zapier projects. Instead of trying to create a universal function, you can use a higher-order function to generate the pre-custom trigger fields for each key. Here’s how I’ve implemented it:
function createPreCustomTriggerFields(doSomething) {
return function(bundle) {
doSomething();
// Add any common logic here
return bundle.inputData;
};
}
const commonLogic = () => {
// Your common logic here
};
module.exports = {
TRIGGERKEY1_pre_custom_trigger_fields: createPreCustomTriggerFields(commonLogic),
TRIGGERKEY2_pre_custom_trigger_fields: createPreCustomTriggerFields(commonLogic),
TRIGGERKEY3_pre_custom_trigger_fields: createPreCustomTriggerFields(commonLogic)
};
This approach keeps the specific trigger key structure intact while allowing you to reuse the same logic across multiple triggers. It’s been a game-changer for me in terms of code maintainability and reducing repetition. Give it a shot and see if it works for your use case!