Coordinating Asynchronous REST Responses in UI Builder
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2025 09:54 AM - edited 06-20-2025 09:55 AM
Hi community,
I’m building a scoped app with a custom Workspace (Next Experience UI Builder) and need to call an external API asynchronously (we’re following the Store guidelines of using RESTMessageV2.executeAsync() for outbound calls). Our setup is as follows:
- Data Resource 1 (Transform Data Broker): Sends the API request via executeAsync(), generates a correlation ID, and inserts a record in a custom “cache” table with status = “pending.”
- After-insert Business Rule on ecc_queue: Matches the response via the correlation ID and updates the cache record to status = “complete,” saving the API response data.
- Data Resource 2 (Transform Data Broker): Queries the cache table by the same correlation ID to fetch the response data.
- Text Component: Bound to Data Resource 2 to display the final result.
The problem is that Data Resource 2 (and thus the UI) often refreshes before the external API reply arrives. We currently trigger Data Resource 2 from a “Data Fetch Succeeded” event handler on Resource 1, but since the API call takes ~1 second, the cache record is still pending and the UI shows empty data. In short, the UI updates too early.
Questions: What is the recommended way in UI Builder to reliably detect when the async response is available and refresh the data or component? Are there better patterns or features in UI Builder to coordinate an async REST response with updating the UI?
Note on design choice: I opted to use a custom cache table to store the async API response rather than querying the ecc_queue table directly from my Data Resource. This is because ecc_queue is a ServiceNow system table, and reading from it directly in scoped apps could be not recommended and not Store-compliant. If anyone has also any feedback on this approach or alternative best practices, I’d appreciate validation or suggestions.
Thanks in advance for any suggestions or references to relevant documentation!