Loading...

Calling Web Functions from a Workbook


You can call Web Functions from Workbooks using the WebApi Action, and then use the HttpGet(…), HttpPost(…), HttpPut(…), HttpPatch(…) or HttpDelete(…) methods to configure the request.

All the Http methods returns a response handle that you can use to obtain any data returned from a Web Function once the WebApi action has completed. The response handle has a Data property that contains the actual data returned from the Web Function, for example a string, a business object, an array of objects and so on.


Example 1

This example shows how to call a Web Function from a Workbook by issuing a HTTP Put request. First, you need to invoke a WebApi Action. The WebApi Action is an action available on the Workbook Object itself.

In the WebApi Action instructions list, call the HttpPut method to configure the request with the url and payload.

In the WebApi Action instructions list:

HttpPut("api/webfunctions/My_Web_Function1", {"CustomerID" : _selectedCustomer.ID, "Name" : Input_CustomerName.Value});

Example 2

This example shows how to call a Web Function from a Workbook and read the data returned from the request.

Calling HttpGet(…) returns a handle that you can use obtain the data returned from the Web Function once the WebApi action completes. The response handle has a Data property that contains the data returned by the Web Function.

In the WebApi Action instructions list:

_responseHandle = HttpGet("api/webfunctions/My_Web_Function2?customerId=" + _selectedCustomer.ID);

Once the WebApi action completes, the data returned by the Web Function is available from the Data property of the response handle.

So if the Web Function returns a customer object with a CustomerName property, you can get the customer name by simply accessing that property.

ShowToastNotification("Customer Name", _responseHandle.Data.CustomerName);
ShowToastNotification("Update",Filter("Filters", "Dept").SelectedValue.Id);