How to create a reusable function?

Is it possible to create a reusable function, see example below, that can be called with arguments within a component? I am attempting to format multiple values in different components placed on a single retool page while trying to do so without having to redefined the function within each component.

It would be ideal if I can do something like this {{ reusableFunction(selectedRow.col1.value, selectedRow.col2.value) }} for each applicable component rather than this {{ selectedRow.col1.value + selectedRow.col2.value }}.

resource - reusableFunction

function reusableFunction(arg1, arg2) {
     return arg1 + arg2
}

@brichardson

Hey there :wave: You could write a global function if you head to App Actions > Scripts and styles > Javascript:

This function you can then call anywhere in your app:

3 Likes

thank you very much this is exactly what I was looking for! :pray:

Hi all,

Related to this thread -- we just launched a closed alpha for Sync Functions. Let me know if you'd like to be added!

Best,
Erin