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

Hello all, this is Retool from the future! :smiling_face_with_sunglasses: Earlier this year in March 2025, we launched App Functions Beta, which is the updated version of the Sync Functions Erin mentioned above.

App functions enable you to write reusable logic with dynamic parameters. Use functions when you want to perform the same actions on different pages, with different parameters, and return different data.

We’ve made updates in the app around how to write reusable logic, so check out the latest docs on App Functions! This feature is currently in beta, so let us know if you’d like to be added! :folded_hands:t3: