To use values from data sources in virtual service responses, you need to insert property expansions that refer to the needed data source properties. To do this:
Switch to the Setup page of the virtual service editor.
Select the desired response.
In the property editor on the right, select your data source from the Data Source drop-down list:
Use the property expansion syntax to refer to a property:
${property-name}
– or –
${#MockResponse#property-name}
You can insert these expressions into the response body or into a header. The property names are case-insensitive:
If needed, you can use multiple property expansions, for instance:
Important
For REST service users: The described functionality is available only when the
Response Property Expansion
property istrue
. By default, the property value istrue
. You may need to check it if the property expansion stopped working for some reason.Referring in Scripts
To refer to a data source property in script code, you use the
mockResponse.getPropertyValue(...)
function. The property names are case-insensitive:Important
The
getPropertyValue(...)
function returns the property value in the “property expansion” format. For example,mockResponse.getPropertyValue('City')
will return${City}
, not the actual value of the property like a string or a number. ReadyAPI will handle this expression and insert the actual value before sending the response. This means that you cannot check or compare actual property values in scripts.