Abort Pending REST Calls in VB Studio
When a REST call to your App UI takes too long, you might want to let your users cancel the call midway. You do this by adding an AbortController, a browser-based interface that lets you abort a web request.
Here’s a sample scenario that shows how you can use an AbortController in your App UI. For demo purposes, assume the app has a page with two buttons: a Call REST button and a Cancel REST button.
- When users click the Call REST button, an
ojActionevent triggers an action chain to call theGet/publicWorkers/{publicWorkers_Id}endpoint and displays a notification to the user. - When users click the Cancel REST button, another
ojActionevent triggers an action chain to abort the REST request and display a notification to the user.
Note: The AbortController API is not supported for App UIs that are configured for offline capabilities.
- To use the
AbortControllerAPI, you first need to create anAbortControllerinstance. You also need to call theabortmethod on theAbortControllerinstance that’s created. We’ll do this by adding two app-level JavaScript functions that can be used across your App UI’s pages.-
Select your App UI node, then click JavaScript to open the app-level JavaScript editor.
-
Add this JavaScript snippet to the editor:
/** * Method to create an instance of AbortController. */ createAbortController() { return new AbortController(); } /** * Method to invoke the abort method on the AbortController instance. */ abortRequests(abortController) { abortController.abort(); }Your JS editor might look something like this:

Description of the illustration abortcontroller-js-snippet-appui.png
-
- Create a variable to track the
AbortControllerinstance that will be created.- Click Variables to open the app-level Variables editor.
- Click + Variable and create a variable with ID
abortController(for example) and type Any.
- To initialize the
abortControllervariable when the app loads, build an action chain that’s triggered in response to avbEnterevent for the application.- Click Event Listeners at the app level.
- Click + Event Listener.
- Select vbEnter under Lifecycle events and click Next.
- Select Create Application Action Chain to create a new app-level action chain. Click Finish.
- Click Go to Action Chain next to the newly created
vbEnterListeneraction chain to open the Action Chains editor. - From the Actions palette, drag a Call Function action onto the canvas.
-
In the action’s Function Name property, select
createAbortControllerunder Application to call the JS function that creates anAbortControllerinstance.
Description of the illustration abortcontroller-callfunction.jpg
- Now drag and drop an Assign Variable action to follow the Call Function action.
-
In the Assign Variable action’s Properties pane, select
abortControllerunder Application from the Variable list.
Description of the illustration abortcontroller-assignvariable.jpg
- Hover over the Value property and click
to open the Variables picker, then select createAbortControllerunder Local to assign the value returned by thecreateAbortControllerfunction to yourabortControllervariable.
- Associate the
AbortControllerwith the REST call you want to abort. You do this by attaching theAbortSignalof anAbortControllerinstance to the REST request via thesignaloption. For example, to abort theGet/publicWorkers/{publicWorkers_Id}endpoint request, you attach theAbortSignalto the Call REST action in the action chain underlying the button component (which isButtonActionChainin our example).- Open the action chain that uses the Call REST action in the Action Chains editor. Because our example assumes a Call REST button on a page, this Call REST action exists in the
ButtonActionChainaction chain defined at the page level. - Click Code to switch to code view.
- Locate the code snippet for the particular Call REST action and add this line after the
endpointconstructor:signal: $application.variables.abortController.signal,In this example, the
AbortSignalis accessed via$application.variables.abortController.signaland attached to theget_publicWorkersREST request:
Description of the illustration abortcontroller-abortsignal-appui.png
- Open the action chain that uses the Call REST action in the Action Chains editor. Because our example assumes a Call REST button on a page, this Call REST action exists in the
- To abort REST requests with the
AbortSignalattached, build an action chain to call theabortmethod on theAbortControllerinstance. Because our example assumes a Cancel button that users click to abort theGet/publicWorkers/{publicWorkers_Id}request on a page, we define the abort action chain at the page level (but you can also define it at the app level).- Click Action Chains to open the Action Chains editor.
- Click + Action Chain and create a new action chain with
abortRequestsChainas its ID. - From the Actions palette, drag a Call Function action onto the canvas.
- In the action’s Function Name property, select
abortRequeststo specify the JS function that calls theabortmethod on theAbortControllerinstance for the specific REST request. -
To pass your
abortControllervariable as an input parameter to theabortRequestsfunction, locate theabortControllerunder Parameters, hover over the parameter to open the Variables picker, then selectabortControllerunder Application.
Description of the illustration abortcontroller-mapinputparam1.jpg
-
Calling the
abortmethod on anAbortControllerinstance permanently aborts any future requests, so you need to create a newAbortControllerinstance and assign it to theabortControllervariable. To do this, drag and drop a Call Action Chain action and select thevbEnterListeneraction chain (which was created for you in step 3 to do both) in the Action Chain ID list.
Description of the illustration abortcontroller-callactionchain-appui.png
- Add other actions as needed to handle the Cancel operation. For example, you might want to add actions to notify the user and reset anything that’s required for your app’s typical flow.