Skip to main content

External Outputs

External Outputs are used to feed feature outputs into Causal's features from external sources.

For example, extending our example feature:

feature Simple
{
...
output {
simpleOutput : Int! = 42 @external( values: ["BigNumber", "SmallNumber"] )
}
...
}

This means that a user can optionally configure this output from Causal's Tools UI. The output may be configured to either use the BigNumber or the SmallNumber setting to calculate the output's value.

You must implement these settings in your code logic and pass the values back to Causal. The values will be logged back to the data warehouse with all the other impression information.

The first thing to do with an external output is to see if you need to set it. Just because a field has an @external directive, does not mean the it's configured to use one of the external settings. Furthermore, Causal's memoization capabilities may mean that the value has already been computed in a previous call, and should be reused.

if (!req.isSimpleOutputSet()) {}

If the value is not already set, you'll have to compute it and pass it back. In order to do that, call the getOutputNameExternal method, and set the value based on what that returns:

if (!req.isSimpleOutputSet()) {
switch (req.getSimpleOutputExternal()) {
case BigNumber:
req.setSimpleOutput(1000000);
break;
case SmallNumber:
req.setSimpleOutput(2);
break;
}
}