[Download] | [Documentation Home] | [Release Note]

Default Values

Introduction

When defining a data service, a user may have an requirement, that even if a user has not entered a specific parameter value in a request, a default value should be automatically added to the query. This can be done in WSO2 Data Services Server using the default values feature that is found when defining a query.

Setting the Default Value

Figure 1 shows the step in setting a default value for an input-mapping in a query.


Figure 1: Setting a default value to a field.

Referring to Internal Property Values using Default Values

WSO2 Data Services Server defines special system variables, that can be used as a default value. At the moment, it only provides a variable for retreiving the username of the current user who is authenticated in a secured data service. This variable can be accessed by using the following syntax.

  • #{USERNAME} :- This value replaces the current input-mapping value dynamically, with the current user's username, when a data service request is processed at the server.
  • #{NULL} :- This value sets the current input-mapping value to null. This is the same as providing "xsi:nil" in the incoming message's input parameter element.
  • #{TENANT_ID} :- This value represents the current tenant ID, this is meaningful when having a Stratos deployement, where multiple tenants will live in the same server.
  • #{USER_ROLES} :- This value will contain the list of user roles that current calling user will have. If the parameter mapped is of ARRAY type, it will have the full list of user roles, or else if it's a SCALAR, it will only contain the first user role of the user.

Demo

For a demonstration of the usage of default values, refer to the default values demo in the samples.