Skip to main content
Solved

Wait for an async operation to complete before updating the UI with output.text

  • April 16, 2024
  • 2 replies
  • 34 views

Forum|alt.badge.img+6

I added a button to a table that forms a task when the button is clicked.

The task is an async call to a REST API using Javascript's fetch.  I'd like to be able to display the state of the operation, including when its completed.

The code:

// make the REST API with an async function const response = await updateLicense(config.access_token, employeeNumber, licenseNumber); // dispay the results of the processing output.text(response)

 Unfortunately, the code doesn't wait for the updateLicense function to complete.  Any ideas?

Best answer by craibuc

The script works correctly, but I forgot that the webhook is async, so it returns a unique identifier early, rather than the full results when it completed.

2 replies

kuovonne
Forum|alt.badge.img+29
  • Brainy
  • April 16, 2024

What does the rest of the script look like, including the updateLicense() function? Is it an async function where you await the fetch?


Forum|alt.badge.img+6
  • Author
  • Inspiring
  • Answer
  • April 19, 2024

The script works correctly, but I forgot that the webhook is async, so it returns a unique identifier early, rather than the full results when it completed.