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.

v_query - getCondition(String field)

Gets an encoded query string for the specified field.

See also v_table API.

Table 1. Parameters
Name Type Description
field String Name of the field.
Table 2. Returns
Type Description
String Returns an encoded query string for the given field.

Example

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.

Table 3. Parameters
Name Type Description
None
Table 4. Returns
Type Description
String The encoded query as a string.

Example

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.

Table 5. Parameters
Name Type Description
field String Name of the field to be queried.
Table 6. Returns
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".

Example

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.

Table 7. Parameters
Name Type Description
None
Table 8. Returns
Type Description
String Sys_id value in the get query, for example, if sys_id=123, this method returns 123.

Example

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.

Table 9. Parameters
Name Type Description
None
Table 10. Returns
Type Description
String Text search query parameter, for example email.

Example

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.

Table 11. Parameters
Name Type Description
None
Table 12. Returns
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.

Example

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.

Table 13. Parameters
Name Type Description
None
Table 14. Returns
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.

Example

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.

Table 15. Parameters
Name Type Description
message String Error message.
Table 16. Returns
Type Description
None

Example

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);

Example

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);