URI encoding in pre-req

This curl works:

curl --insecure \
     --header "auth: ${sessionID}" \
     --header "X-API-Version: ${currentVersion}" \
     --request GET ${OneView}/rest/server-hardware?filter=%22%27serverName%27%20=%20%27my-host%27%22`

I defined SERVER with the FQDN in the environment. I’m trying to set a variable in the pre-req section to hold the encoded value. I tried:

var encoded = encodeURIComponent("'serverName' = '{{SERVER}}'");

but encoded never seems to get defined. In the Params section I put
filter {{encoded}}

What am I doing wrong?

You can’t use the handlebars method within the scripts (pre-request or tests tab) like you can in the params section.

If you want to retrieve a variable in a script you have to use a different method.