Functions
Last updated
Last updated
Functions allow you to create short scripts that can be later reused in in any of your other scripts.
To create a function, select Add new function script
button.
Function arguments are automatically injected into function code. At the end of the function you should return response using return
tag.
Example: Send metrics to Klaviyo using Klaviyo API.
Here is the code of the function:
Above code creates a payload and sends it as HTTP requestt to Klaviyo API. Variable payload is scoped to the function and created when function is called. Here is how you should call this function from any other script:
To invoke a function you use function
tag followed by function handle and function input.
After execution, fn_result
contains result of HTTP call made in send_metric_to_klaviyo function.
There are few limitiations to keep in mind when using functions:
task variables are not available in functions (you can pass it as function input)
you can access global variables in functions
you can't invoce another function inside function