Overview
This guide explains how to leverage a Functionize Extension as a pre-hook to modify a value extracted from a webpage, specifically to convert it to uppercase, before it is used in a subsequent input step.
Goal: Read a value from the local variable
fze.local.capturedValue, convert it to uppercase, and overwrite the same variable so the next step uses the modified text.
Scenario & Workflow
Extraction: A value is extracted from the webpage and automatically stored in a local variable, e.g.,
fze.local.capturedValue.Pre-hook Trigger: The Extension is attached as a pre-hook to the target Input Step. It executes before the input action runs.
Extension Logic: The Extension performs the following operations:
Reads the current value of the local variable.
Converts the text to UPPERCASE.
Returns the updated (uppercase) value back into the same local variable (
fze.local.capturedValue).
Input Execution: The Input Step runs immediately after the pre-hook completes, using the updated, uppercase value from
fze.local.capturedValue.
Extension Code (Java)
This Java code snippet is deployed as a Functionize Extension and handles the logic for reading the variable, converting the text, and returning the updated value in the expected JSON format.
Sample example-
package com.functionize;
import com.google.cloud.functions.HttpFunction;
import com.google.cloud.functions.HttpRequest;
import com.google.cloud.functions.HttpResponse;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
public class Example implements HttpFunction {
@Override
public void service(HttpRequest request, HttpResponse response) throws IOException {
// 1. Parse incoming JSON request body
Gson gson = new Gson();
JsonObject requestBody = gson.fromJson(
new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8),
JsonObject.class
);
// 2. Read the local variable that holds the captured text
String originalValue = requestBody
.getAsJsonObject("variables")
.getAsJsonObject("local")
.get("capturedValue") // IMPORTANT: Variable name must match test case!
.getAsString();
System.out.println("Incoming value: " + originalValue);
// 3. Convert the text to uppercase
String upperValue = originalValue.toUpperCase();
System.out.println("Uppercase value: " + upperValue);
// 4. Build Functionize-compatible response JSON to update the variable
String jsonResponse = "{"
+ "\"updates\": {"
+ "\"variables\": {"
+ "\"local\": {"
+ "\"capturedValue\": \"" + upperValue + "\""
+ "}"
+ "}"
+ "}"
+ "}";
// 5. Send the JSON response
response.setContentType("application/json");
BufferedWriter writer = response.getWriter();
writer.write(jsonResponse);
}
}
Implementation Notes
Attachment: The Extension must be attached as a pre-hook to the specific input action where the uppercase value is required.
Variable Naming: The local variable name used in the Extension code (
"capturedValue") and the variable used in the Functionize test step (fze.local.capturedValue) must match exactly.