v_query – Scoped, Global
The v_query API provides methods to obtain information about a scriptable object that represents a query running against a remote table.
This API requires the Remote Tables plugin (com.glide.script.vtable) to be activated. For additional information, see Retrieving external data using remote tables and scripts.
Remote table rows are created using the v_table API.
Parent Topic:Server API reference
v_query - getCondition(String field)
Gets an encoded query string for the specified field.
See also v_table API.
| Name | Type | Description |
|---|---|---|
| field | String | Name of the field. |
| Type | Description |
|---|---|
| String | Returns an encoded query string for the given field. |
The following example shows results for a field with an encoded query of number=INC0001^active=true.
var result = v_query.getCondition("number");
gs.info(result);
Output:
number=INC0001
v_query - getEncodedQuery()
Returns the query against a remote table as an encoded query string
For details, see Encoded query strings.
See also v_table API.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| String | The encoded query as a string. |
The following example is a snippet from Retrieving specific records from a third-party source.
gs.info(v_query.getEncodedQuery());
Output:
active=true^priority=1
v_query - getParameter(String field)
Gets the value of a field in an equality query condition.
See also:
| Name | Type | Description |
|---|---|---|
| field | String | Name of the field to be queried. |
| Type | Description |
|---|---|
| String | Value of the field in the query condition. For example, if name=John is the encoded query, then getParameter("name") returns "John". |
The following example shows how to get the value of a caller ID field.
v_query.getParameter("caller_id");
Output:
12345123451234512345123451234501
v_query - getSysId()
Returns the sys_id value in a get query.
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| String | Sys_id value in the get query, for example, if sys_id=123, this method returns 123. |
The following example is a snippet from Retrieving specific records from a third-party source.
v_query.getSysId();
Output:
a3a7ffb6dba41010db2051735e4619b7
v_query - getTextSearch()
Gets a text search query parameter.
See also:
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| String | Text search query parameter, for example email. |
In the following example, the method returns true if the query contains a text query parameter, such as GOTO123TEXTQUERY321=email.
// for query value GOTO123TEXTQUERY321=email
v_query.getTextSearch();
Output:
email
v_query - isGet()
Determines if the query is a get query, that is, a query that retrieves a record by sys_id.
See also:
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| Boolean | Flag indicates that query for a specific record has `sys_id=` as the query format. Valid values: - true: Query contains equality query condition on the sys\_id field. - false: Query does not include equality query condition on the sys\_id field. |
In the following example, if the encoded query is sys_id=d1954c744662010bd7e061e67a6776e, the v_query.isGet() method returns true. If the encoded query is anything else, such as Number=INC0000001, the v_query.isGet() method returns false.
// Virtual table to query
var row = {
sys_id: "d1954c744662010bd7e061e67a6776e",
number: "INC0000001",
short_description: "New laptop request",
u_balance: 1200.23
};
v_table.addRow(row);
v_query.isGet();
v_query - isTextSearch()
Indicates if the query contains a text query parameter.
See also:
| Name | Type | Description |
|---|---|---|
| None |
| Type | Description |
|---|---|
| Boolean | Flag that indicates whether the query contains a text query parameter.Valid values: - true: Query contains a text query parameter. - false: Query does not contain a text query parameter. |
In the following example, the method returns true if the query contains a text query parameter, such as GOTO123TEXTQUERY321=email.
v_query.isTextSearch();
v_query - setLastErrorMessage(String message)
Sets the last error message in the GlideRecord.
See also:
- Scoped GlideRecord - getLastErrorMessage()
- Retrieving specific records from a third-party source
- v_table API
| Name | Type | Description |
|---|---|---|
| message | String | Error message. |
| Type | Description |
|---|---|
| None |
The following example shows the basic structure used to set an error message.
(function executeQuery (v_table, v_query) {
try {
// Add code to test for errors during execution
} catch(ex) {
v_query.setLastErrorMessage(ex.message);
}
}) (v_table, v_query);
The following example shows how to set the last error message in a REST API.
(function executeQuery (v_table, v_query) {
try {
// call a REST API
} catch(ex) {
v_query.setLastErrorMessage("Error obtaining results from remote service");
}
}) (v_table, v_query);