Welcome to the Airtable Community! If you're new here, check out our Getting Started area to get the most out of your community experience.

Is it possible to put a button within a function?

Topic Labels: Scripting extentions
943 3
Showing results for 
Search instead for 
Did you mean: 

I’m pretty new to JS, but trying to learning all the time.
Some of the first code I wrote in the scripting blog has gotten supper hard to update, so thought to experiment to write small modules to keep divide up the code.

However it seems I can’t put buttons into functions?

let test = function () {

    let firstClick = await input.buttonsAsync(
    'What do you want to do?',
    {label: 'Check todays rate', value: 'today', variant: 'danger'},
    {label: 'Convert currency', value: 'convert', variant: 'primary'}

this gives me an error saying ‘SyntaxError: await is only valid in async function’
does theis mean my button can only be used in the global scope?

3 Replies 3

You can put buttons in functions. You just need to make the function an async function and await it when you call it.

let test = async function () {
  let firstClick = await input.buttonsAsync( ...

await test();

Sorry for the late reply, but didn’t completely understand it until I dug a bit deeper in JS and Async Await functions. Now it makes perfect sense.

THANK YOU FOR THIS :slightly_smiling_face: I was pulling my hair out and now have it working!