The CreatorCon Call for Content is officially open! Get started here.

How to trigger async REST call from Button in Workspace

Piotr Sadowski1
Tera Contributor

Hi everyone,

I'm fairly new to the Now Experience and currently working on a SIR Workspace where I need to add a button that:

  1. Triggers an asynchronous REST call to an external service.
  2. Once the call completes, reloads the data in a Data Resource called "Look up data 1" [look_up_data_1] attached to the "Rich text 10" [rich_text_10].

Right now, I’ve implemented this using a UI Action with the following setup:

  • Checked Workspace Form Button and Workspace Client Script.
  • In the Workspace Client Script, I use GlideAjax to call a Script Include, which then triggers the REST call via RESTMessageV2.
  • I’ve also configured the REST Message, HTTP Method, and a System Property to load the endpoint configuration.

This setup works, but I’d like to move this logic into UI Builder, using a Button component, so it’s fully integrated with Workspace and more maintainable, and be able to reload content of Data Resource.

Unfortunately, I’m not sure how to:

  • trigger the REST call from the Button component.
  • wait for the response.
  • then reload the Data Resource.

Here’s the current Workspace Client Script for reference:

function onClick(g_form) {
	var sysId = g_form.getUniqueValue();

    var ga = new GlideAjax('Custom_ScriptInclude');
    ga.addParam('sysparm_name', 'triggerAjax');
    ga.addParam('sysparm_security_incident_sysid', sysId);
    ga.getXMLAnswer(function(response) {
		g_form.reload();
    });
}
 

Any guidance or examples on how to achieve this in UI Builder would be greatly appreciated!

Thanks in advance!

1 REPLY 1