splunksignalfx

Splunk SignalFX Synthetics: Is it possible to retrieve environment variable values in Javascript


For API Test, I need to read the existing environment variables and do some small calculation and set the new value to a new environment variable. (Possible in Postman).

How can I do this? I am thinking of retrieving the values and performing the calculation in "Javascript" option.

Can I retrieve the environment variable values from Javascript option either in Setup or in Validation step?

Here is the screenshot: enter image description here

I could not find any examples in Splunk documentation https://splunk.github.io/observability-workshop/v5.64/en/other/11-synthetics-scripting/2-api-test/index.html


Solution

  • Environment variables are injected into the JavaScript context as variables, so you don't need the double braces. So you should be able to do:

    const variableValue = custom.varname;
    variableValue;
    

    The API Test is largely based on the API Check from a company called Rigor that Splunk acquired.

    Please note that you have to keep the variable names simple like in camelCase instead of using any special characters like hyphen(-) etc in the variable name. This works in other steps but the environment variables that you want to use in Javascript step should have simple name. Else the step seems to fail