Appsmith lets us write IIFE (Immediately Invoked Function Expression) Javascript function inside the moustache bindings anywhere across the platform.
IIFE
(function () {
/* ... */
})();
Arrow function IIFE
(() => {
/* ... */
})();
async IIFE
(async () => {
/* ... */
})();
Here’s an example of how we can run queries or APIs with a custom body inside the function using JS Objects:
export default {
runMyApi: async () => {
// store value
await storeValue('myFirstValue', Input1.text)
await storeValue('mySecondValue', Table1.selectedRow)
// run API calls
await myApiCall.run()
// Optionally reset the values in the store in case you don't need to keep them around.
await storeValue('myFirstValue', undefined)
await storeValue('mySecondValue', undefined)
}
}