mwthoreso
4 years agoNew Contributor
Script - Virtual Service Dispatch - JavaScript return value (setting Reponse)
Hi, with the default Groovy scripts you configure your Response Dispatch with a `return` value, the value being the name of the response:
if ( yourVariable.equals("somestring"))
{
return "Success" // "Success" is the name of the Response you've configured
}
Well, in JavaScript you can't just return in the main portion of the script, you can only return from a function/method.
What specifically do we need to set (in JavaScript) to tell ReadyAPI which Response to set?
There are some objects for us to view, but it won't seem to let me manipulate them. I can find the default Response:
log.info(mockOperation.defaultResponse)
But I can't figure out how to set a Response. I get errors like this:
context.MockResponse.setName("Error")
Yields error:
TypeError: Cannot call method "setName" of null
Same general error for context.MockResponse.setResponseContent()