Overriding generated functions to provide custom behavior

Code for the formula that Platform generates is divided into two sections as shown in the screen below.

REST Service generated code

You should not change any code in the second section, labeled Generated code. If you change request and/or response mappings, Platform regenerates this section of code.

The code in the first section contains function definitions that you can edit to customize processing and formatting. Platform does not regenerate this code when you change mappings.

The functions you can edit and customize include:

  • formatDate() — Converts Date fields from Platform to a standard format accepted by the Decision Service. Edit this function to change the format.
  • formatDateTime() — Converts DateTime fields from Platform to a standard format accepted by the Decision Service. Edit this function to change the format.
  • updateURL(url) — Manipulates the URL before invoking request
  • processRestRequestData() — Converts simple JSON object that includes all mappings as properties of the object for PUT/POST calls.
  • processRestResponse() — Updates any record value or persists REST response to some Platform field.
  • convertResponseData() — Handles REST response and converts data to corresponding format based on Platform field data type. This ensures that create or update records works.
  • beforeStart() — Runs before invoking REST endpoint. REST endpoint URL, headers (if you added mapping under the header tab), and request data are passed as arguments of this method. If a GET call is made, the request data parameter is null. This callback method enables you to write any pre-trigger execution code such as invoking some other trigger or calling any other server-side API.
  • afterComplete() — Runs after the REST trigger execution is completed. Response data is passed as a string and a JSON object. This callback method enables you to write any pre-trigger execution code such as invoking some other trigger or calling any other server-side API.

Example customization

The example below shows how to override the processRestResponse() function to save the response in a field in the Infinite Blue record:

function processRestResponse(jsonResponseString, jsonResponseObject, 
requestDuration, requestStartDate)
{    /* Add post processing to the REST response before writing fields and objects
 in Rollbase - by default we leave it untouched. */
    // Example saving response to a field: rbv_api.setFieldValue
('ObjectName', '{!id}', 'Trace_Rest_Response', jsonResponseString);
     rbv_api.setFieldValue("Building", '{!id}', "Rest_Response", jsonResponseString);
  return jsonResponseObject;}

The View page for Infinite Blue includes the response in the configured field:

REST Service response cust