GlideDBFunctionCaseBuilder - Global
-
- UpdatedAug 1, 2024
- 6 minutes to read
- Xanadu
- API reference
The GlideDBCaseStatementBuilder API allows you to build SQL CASE statements and return values based on a series of conditions.
You can use this API as part of the definition of the GlideElement - Global API or when querying a table. To build a CASE
statement, start by instantiating the GlideDBFunctionCaseBuilder object using its constructor,
GlideDBFunctionCaseBuilder(). Then, define one or more cases using a series of when() and then() calls followed by a single, optional otherwise() call.
Lastly, call the build() method to finalize the builder and produce the completed database function case statement. This statement can then be used directly or as part of other Glide function definitions.
Required roles: Admin, function_field_admin.
GlideDBFunctionCaseBuilder - GlideDBFunctionCaseBuilder()
Instantiates a GlideDBFunctionCaseBuilder object.
Name | Type | Description |
---|---|---|
None |
Example
This example instantiates a GlideDBFunctionCaseBuilder object.
GlideDBFunctionCaseBuilder - build()
Concludes the list of conditions and builds the final CASE statement.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
string | The completed case statement. |
Example
The following example shows how to define and build a simple case statement. Depending on the numerical value of the impact field, it will output one of four different strings.
Output:
GlideDBFunctionCaseBuilder - otherwise(String exp)
Optional. Following at least one pair of calls to when and then, the otherwise() call allows you to specify a value to output if none of the when expressions are satisfied.
Name | Type | Description |
---|---|---|
exp | String | Value to output. Can be a constant, a reference to a field, or another Glide function. |
Type | Description |
---|---|
GlideDBFunctionCaseBuilder | The fluent builder object to continue building the statement. |
Example
The following example shows how to define and build a simple case statement.
Output:
GlideDBFunctionCaseBuilder - then(String exp)
Following any when() method, then() allows you to specify a value to output if the when() expression is satisfied.
Name | Type | Description |
---|---|---|
exp | String | Value to output. Can be a constant, reference to a field, or another Glide function. |
Type | Description |
---|---|
GlideDBFunctionCaseBuilder | The fluent builder object to continue building the statement. |
Example
The following example shows how to define and build a simple case statement. In this case, the then() expressions show how you can output not only strings, but also the results of other glide functions such as
the length(short_description)
.
Output:
GlideDBFunctionCaseBuilder - when(String func)
The most versatile of the supported 'when' expressions, the when() method allows you to supply any boolean-valued Glide function as the condition to satisfy.
Name | Type | Description |
---|---|---|
func | String | A Glide function that results in a boolean-valued result when evaluated. Possible values:
|
Type | Description |
---|---|
glideDBFunctionCaseBuilder | The object to continue building the statement. |
Example
The following example shows how to define and build a simple case statement. In this case, the when() method is used to specify more complex comparison expressions. If the expression evaluates to true, the corresponding string is returned.
Output:
GlideDBFunctionCaseBuilder - whenCompare(String exp1, String op, String exp2)
Begins a comparison case condition.
Name | Type | Description |
---|---|---|
exp1 | String | Left comparison expression. Can be a constant, reference to a field, or another Glide function. |
op | String | Comparison operator, surrounded with quotes. Valid values:
|
exp2 | String | Right comparison expression. Can be a constant, reference to a field, or another Glide function. |
Type | Description |
---|---|
GlideDBFunctionCaseBuilder | The function builder object to continue building the statement. |
Example
The following example shows how to define and build a simple case statement. In this case, the whenCompare() method is used to compare the value of the impact field to a number and output a specified string if they match.
Output:
GlideDBFunctionCaseBuilder - whenEqual(String exp1, String exp2)
Similar to whenCompare(), whenEqual() is a convenient method for checking equality. It is equivalent to whenCompare(leftExpression, ‘=’, rightExpression).
Name | Type | Description |
---|---|---|
exp1 | String | Left comparison expression. Can be a constant, a reference to a field, or another Glide function. |
exp2 | String | Right comparison expression. Can be a constant, a reference to a field, or another Glide function. |
Type | Description |
---|---|
GlideDBFunctionCaseBuilder | The function builder object to continue building the statement. |
Example
The following example shows how to define and build a simple case statement. In this case, the whenEqual() method is used to compare the value of the impact field to a number and output a specified string if they match.
Output:
On this page
- GlideDBFunctionCaseBuilder - GlideDBFunctionCaseBuilder()
- GlideDBFunctionCaseBuilder - build()
- GlideDBFunctionCaseBuilder - otherwise(String exp)
- GlideDBFunctionCaseBuilder - then(String exp)
- GlideDBFunctionCaseBuilder - when(String func)
- GlideDBFunctionCaseBuilder - whenCompare(String exp1, String op, String exp2)
- GlideDBFunctionCaseBuilder - whenEqual(String exp1, String exp2)