---
sourceDocument: Xanadu API Reference
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/xanadu/api-reference

 Release :

    - xanadu

ft:locale :

    - en-US

ft:publication_title :

    - Xanadu API Reference

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# v_query -- Scoped, Global

# v_query -- Scoped, Global {#ariaid-title1}

* Release version: Xanadu
* 
* Updated August 1, 2024
* 
* ![](https://www.servicenow.com/docs/portal-asset/ico-clock) 3 minutes to read

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](https://www.servicenow.com/docs/access?context=remote-tables&version=xanadu&pubname=xanadu-servicenow-platform&ft:locale=en-US).

Remote table rows are created using the [v_table](https://servicenow-prod.fluidtopics.net/S0jZRyXM~OZl6q~33LQWlQ#v_tableAPI "The v_table API provides methods to add rows to a remote table through a scriptable object.") API.

## v_query - getCondition(String field) {#ariaid-title2}

Gets an encoded query string for the specified field.
See also [v_table](https://servicenow-prod.fluidtopics.net/S0jZRyXM~OZl6q~33LQWlQ#v_tableAPI "The v_table API provides methods to add rows to a remote table through a scriptable object.") API.
{#vquery-getCondition_S__table_j3v_xm3_nlb__entry__3}

| Name | Type | Description |
|-|-|-|
| field | String | Name of the field. |
[Table 1. Parameters]

{#vquery-getCondition_S__table_j3v_xm3_nlb} {#vquery-getCondition_S__table_k3v_xm3_nlb__entry__2}

| Type | Description |
|-|-|
| String | Returns an [encoded query string](https://www.servicenow.com/docs/access?context=c_EncodedQueryStrings&version=xanadu&pubname=xanadu-platform-user-interface&ft:locale=en-US) for the given field. |
[Table 2. Returns]

{#vquery-getCondition_S__table_k3v_xm3_nlb}  
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() {#ariaid-title3}

Returns the query against a remote table as an encoded query string
For details, see [Encoded query
strings](https://www.servicenow.com/docs/access?context=c_EncodedQueryStrings&version=xanadu&pubname=xanadu-platform-user-interface&ft:locale=en-US) .{#vquery-getEncodedQuery__link_encoded_query_strings}

See also [v_table](https://servicenow-prod.fluidtopics.net/S0jZRyXM~OZl6q~33LQWlQ#v_tableAPI "The v_table API provides methods to add rows to a remote table through a scriptable object.") API.
{#vquery-getEncodedQuery__table_j3v_xm3_nlb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 3. Parameters]

{#vquery-getEncodedQuery__table_j3v_xm3_nlb} {#vquery-getEncodedQuery__table_k3v_xm3_nlb__entry__2}

| Type | Description |
|-|-|
| String | The encoded query as a string. |
[Table 4. Returns]

{#vquery-getEncodedQuery__table_k3v_xm3_nlb}  
The following example is a snippet from [Retrieving specific records from a
third-party source](https://www.servicenow.com/docs/access?context=remote-table-script-def-example2&version=xanadu&pubname=xanadu-servicenow-platform&ft:locale=en-US).

    gs.info(v_query.getEncodedQuery());

Output:

    active=true^priority=1

## v_query - getParameter(String field) {#ariaid-title4}

Gets the value of a field in an equality query condition.
See also:

* [Retrieving specific records from a
  third-party source](https://www.servicenow.com/docs/access?context=remote-table-script-def-example2&version=xanadu&pubname=xanadu-servicenow-platform&ft:locale=en-US)
* [v_table](https://servicenow-prod.fluidtopics.net/S0jZRyXM~OZl6q~33LQWlQ#v_tableAPI "The v_table API provides methods to add rows to a remote table through a scriptable object.") API
{#vquery-getParameter_S__ul_y54_hnd_sqb} {#vquery-getParameter_S__table_j3v_xm3_nlb__entry__3}

| Name | Type | Description |
|-|-|-|
| field | String | Name of the field to be queried. |
[Table 5. Parameters]

{#vquery-getParameter_S__table_j3v_xm3_nlb} {#vquery-getParameter_S__table_k3v_xm3_nlb__entry__2}

| 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"`. |
[Table 6. Returns]

{#vquery-getParameter_S__table_k3v_xm3_nlb}  
The following example shows how to get the value of a caller ID field.

    v_query.getParameter("caller_id");

Output:

    12345123451234512345123451234501

## v_query - getSysId() {#ariaid-title5}

Returns the sys_id value in a get query.
{#vquery-getSysId__table_j3v_xm3_nlb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 7. Parameters]

{#vquery-getSysId__table_j3v_xm3_nlb} {#vquery-getSysId__table_k3v_xm3_nlb__entry__2}

| Type | Description |
|-|-|
| String | Sys_id value in the get query, for example, if `sys_id=123`, this method returns 123. |
[Table 8. Returns]

{#vquery-getSysId__table_k3v_xm3_nlb}  
The following example is a snippet from [Retrieving specific records from a
third-party source](https://www.servicenow.com/docs/access?context=remote-table-script-def-example2&version=xanadu&pubname=xanadu-servicenow-platform&ft:locale=en-US).

    v_query.getSysId();

Output:

    a3a7ffb6dba41010db2051735e4619b7

## v_query - getTextSearch() {#ariaid-title6}

Gets a text search query parameter.
See also:

* [Encoded query strings](https://www.servicenow.com/docs/access?context=c_EncodedQueryStrings&version=xanadu&pubname=xanadu-platform-user-interface&ft:locale=en-US)
* [Querying tables in script](https://www.servicenow.com/docs/access?context=c_UsingGlideRecordToQueryTables&version=xanadu&pubname=xanadu-application-development&ft:locale=en-US)
* [v_table](https://servicenow-prod.fluidtopics.net/S0jZRyXM~OZl6q~33LQWlQ#v_tableAPI "The v_table API provides methods to add rows to a remote table through a scriptable object.") API
{#vquery-getTextSearch__ul_a2q_rkp_nlb}
{#vquery-getTextSearch__table_j3v_xm3_nlb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 9. Parameters]

{#vquery-getTextSearch__table_j3v_xm3_nlb} {#vquery-getTextSearch__table_k3v_xm3_nlb__entry__2}

| Type | Description |
|-|-|
| String | Text search query parameter, for example email. |
[Table 10. Returns]

{#vquery-getTextSearch__table_k3v_xm3_nlb}  
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() {#ariaid-title7}

Determines if the query is a get query, that is, a query that retrieves a record by
sys_id.
See also:

* [Retrieving specific records from a
  third-party source](https://www.servicenow.com/docs/access?context=remote-table-script-def-example2&version=xanadu&pubname=xanadu-servicenow-platform&ft:locale=en-US)
* [v_table](https://servicenow-prod.fluidtopics.net/S0jZRyXM~OZl6q~33LQWlQ#v_tableAPI "The v_table API provides methods to add rows to a remote table through a scriptable object.") API
{#vquery-isGet__ul_y54_hnd_sqb} {#vquery-isGet__table_j3v_xm3_nlb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 11. Parameters]

{#vquery-isGet__table_j3v_xm3_nlb} {#vquery-isGet__table_k3v_xm3_nlb__entry__2}

| 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. {#vquery-isGet__ul_jdl_pfb_add} |
[Table 12. Returns]

{#vquery-isGet__table_k3v_xm3_nlb}  
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() {#ariaid-title8}

Indicates if the query contains a text query parameter.
See also:

* [Encoded query strings](https://www.servicenow.com/docs/access?context=c_EncodedQueryStrings&version=xanadu&pubname=xanadu-platform-user-interface&ft:locale=en-US)
* [Querying tables in
  script](https://www.servicenow.com/docs/access?context=c_UsingGlideRecordToQueryTables&version=xanadu&pubname=xanadu-application-development&ft:locale=en-US)
* [v_table](https://servicenow-prod.fluidtopics.net/S0jZRyXM~OZl6q~33LQWlQ#v_tableAPI "The v_table API provides methods to add rows to a remote table through a scriptable object.") API
{#vquery-isTextSearch__ul_a2q_rkp_nlb}
{#vquery-isTextSearch__table_j3v_xm3_nlb__entry__3}

| Name | Type | Description |
|-|-|-|
| None |   |   |
[Table 13. Parameters]

{#vquery-isTextSearch__table_j3v_xm3_nlb} {#vquery-isTextSearch__table_k3v_xm3_nlb__entry__2}

| 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. {#vquery-isTextSearch__ul_jdl_pfb_add} |
[Table 14. Returns]

{#vquery-isTextSearch__table_k3v_xm3_nlb}  
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) {#ariaid-title9}

Sets the last error message in the GlideRecord.
See also:

* [Scoped
  GlideRecord - getLastErrorMessage()](https://servicenow-prod.fluidtopics.net/Z64TK~kWnpWTEG5bCPvZuQ#c_GlideRecordScopedAPI "The scoped GlideRecord API is used for database operations.")
* [Retrieving specific records from a
  third-party source](https://www.servicenow.com/docs/access?context=remote-table-script-def-example2&version=xanadu&pubname=xanadu-servicenow-platform&ft:locale=en-US)
* [v_table](https://servicenow-prod.fluidtopics.net/S0jZRyXM~OZl6q~33LQWlQ#v_tableAPI "The v_table API provides methods to add rows to a remote table through a scriptable object.") API
{#vquery-setLastErrorMessage_S__ul_dbm_rvc_sqb}
{#vquery-setLastErrorMessage_S__table_j3v_xm3_nlb__entry__3}

| Name | Type | Description |
|-|-|-|
| message | String | Error message. |
[Table 15. Parameters]

{#vquery-setLastErrorMessage_S__table_j3v_xm3_nlb} {#vquery-setLastErrorMessage_S__table_k3v_xm3_nlb__entry__2}

| Type | Description |
|-|-|
| None |   |
[Table 16. Returns]

{#vquery-setLastErrorMessage_S__table_k3v_xm3_nlb}  
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);


