I have a Javascript policy with the following code:
var scenario = context.proxyRequest.queryParams['scenario']; switch (scenario) { case "abc": print("Case is abc"); break; case "xyz": print("Case is xyz"); break; default: print("No Match: The value of scenario is: " + scenario); }
My URL is https://abc.com/test?scenario=abc
I am finding that the code falls into the "Default" path and it prints:
No Match: The value of scenario is: abc
so it confirms that the query parameter was properly extracted and put into the variable scenario.
If so then why doesn't the case: "abc" path get executed? Why does it take the default path?
I hardcoded the value of variable scenario as follows:
var scenario = "abc"
In this case it does go to the case" "abc" path.
Why does it work in the latter case but not in the former case?
Solved! Go to Solution.
Hello Sai,
It worked. Thank you.
I am curious though.
Why didn't the Switch statement work with the following var assignment even though the variable "scenario" had the correct value as confirmed by the Print statement?
var scenario = context.proxyRequest.queryParams['scenario'];