TokenForwarder

Description

The TokenForwarder base class is used for creating custom token forwarders. A token forwarder transforms values from one or more input tokens to an output token. A token forwarder can also validate input tokens, and take special action for invalid input.

Library path

Syntax

var myForwarder = new TokenForwarder(
    ["$inputToken1$", ..., "$inputTokenN"],
    "$outputToken$",
    function(inputTokenVal1, ..., inputTokenValN) {
        ...
        return outputTokenValue;
    }
);

Methods

Name

Description

disposeDestroys the token forwarder.
initializeCreates the token forwarder.

Constants

Name

Description

NO_CHANGEReturn this value from the filtering function to indicate that the output token should not be changed.

Example

// Form a new output token $searchQuery$ from input token $selectedField$
var tf = new TokenForwarder("$selectedField$", "$searchQuery$", function(selectedField) {
    var searchQuery = (selectedField === "message")
        ? "index=_internal | top 3 message"
        : "* | top 3 " + selectedField;
    return searchQuery;
});

// Add a button to stop the token forwarder
$("#stopButton").on("click", function() {
    if (tf) {
        tf.dispose();
        
        $("#stopButton").addClass("disabled");
        tf = null;
    }
});