{"revision":"c10276e953456835cdbb1f3a60d58ae1980be353","document":{"id":1149,"path":"api-reference/server-api-reference/v_queryAPI.md","title":"v\\_query – Scoped, Global","bundle":null,"doc_type":null,"release":"australia","body":"\n# v\\_query – Scoped, Global\n\nThe v\\_query API provides methods to obtain information about a scriptable object that represents a query running against a remote table.\n\nThis 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://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/remote-tables.md).\n\nRemote table rows are created using the [v\\_table](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/v_tableAPI.md) API.\n\n**Parent Topic:**[Server API reference](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/api-server.md)\n\n## v\\_query - getCondition\\(String field\\)\n\nGets an encoded query string for the specified field.\n\nSee also [v\\_table](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/v_tableAPI.md) API.\n\n|Name|Type|Description|\n|----|----|-----------|\n|field|String|Name of the field.|\n\n|Type|Description|\n|----|-----------|\n|String|Returns an [encoded query string](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md) for the given field.|\n\nThe following example shows results for a field with an encoded query of `number=INC0001^active=true`.\n\n```\nvar result = v_query.getCondition(\"number\");\ngs.info(result);\n```\n\nOutput:\n\n```\nnumber=INC0001\n```\n\n## v\\_query - getEncodedQuery\\(\\)\n\nReturns the query against a remote table as an encoded query string\n\nFor details, see [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md).\n\nSee also [v\\_table](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/v_tableAPI.md) API.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|The encoded query as a string.|\n\nThe following example is a snippet from [Retrieving specific records from a third-party source](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/remote-table-script-def-example2.md).\n\n```\ngs.info(v_query.getEncodedQuery());\n```\n\nOutput:\n\n```\nactive=true^priority=1\n```\n\n## v\\_query - getParameter\\(String field\\)\n\nGets the value of a field in an equality query condition.\n\nSee also:\n\n-   [Retrieving specific records from a third-party source](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/remote-table-script-def-example2.md)\n-   [v\\_table](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/v_tableAPI.md) API\n\n|Name|Type|Description|\n|----|----|-----------|\n|field|String|Name of the field to be queried.|\n\n|Type|Description|\n|----|-----------|\n|String|Value of the field in the query condition. For example, if `name=John` is the encoded query, then getParameter\\(\"name\"\\) returns `\"John\"`.|\n\nThe following example shows how to get the value of a caller ID field.\n\n```\nv_query.getParameter(\"caller_id\");\n```\n\nOutput:\n\n```\n12345123451234512345123451234501\n```\n\n## v\\_query - getSysId\\(\\)\n\nReturns the sys\\_id value in a get query.\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Sys\\_id value in the get query, for example, if `sys_id=123`, this method returns `123`.|\n\nThe following example is a snippet from [Retrieving specific records from a third-party source](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/remote-table-script-def-example2.md).\n\n```\nv_query.getSysId();\n```\n\nOutput:\n\n```\na3a7ffb6dba41010db2051735e4619b7\n```\n\n## v\\_query - getTextSearch\\(\\)\n\nGets a text search query parameter.\n\nSee also:\n\n-   [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md)\n-   [Querying tables in script](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/c_UsingGlideRecordToQueryTables.md)\n-   [v\\_table](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/v_tableAPI.md) API\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n|Type|Description|\n|----|-----------|\n|String|Text search query parameter, for example `email`.|\n\nIn the following example, the method returns true if the query contains a text query parameter, such as `GOTO123TEXTQUERY321=email`.\n\n```\n// for query value GOTO123TEXTQUERY321=email\nv_query.getTextSearch();\n```\n\nOutput:\n\n```\nemail\n```\n\n## v\\_query - isGet\\(\\)\n\nDetermines if the query is a get query, that is, a query that retrieves a record by sys\\_id.\n\nSee also:\n\n-   [Retrieving specific records from a third-party source](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/remote-table-script-def-example2.md)\n-   [v\\_table](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/v_tableAPI.md) API\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_k3v_xm3_nlb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag indicates that query for a specific record has `sys_id=` as the query format. Valid values:\n\n-   true: Query contains equality query condition on the sys\\_id field.\n-   false: Query does not include equality query condition on the sys\\_id field.\n\n</td></tr></tbody>\n</table>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.\n\n```\n// Virtual table to query\nvar row = {\n sys_id: \"d1954c744662010bd7e061e67a6776e\",\n number: \"INC0000001\",\n short_description: \"New laptop request\",\n u_balance: 1200.23\n};\n\nv_table.addRow(row);\n\nv_query.isGet();\n```\n\n## v\\_query - isTextSearch\\(\\)\n\nIndicates if the query contains a text query parameter.\n\nSee also:\n\n-   [Encoded query strings](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/platform-user-interface/c_EncodedQueryStrings.md)\n-   [Querying tables in script](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/scripts/c_UsingGlideRecordToQueryTables.md)\n-   [v\\_table](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/v_tableAPI.md) API\n\n|Name|Type|Description|\n|----|----|-----------|\n|None| | |\n\n<table id=\"table_k3v_xm3_nlb\" class=\"returns\"><thead><tr><th>\n\nType\n\n</th><th>\n\nDescription\n\n</th></tr></thead><tbody><tr><td>\n\nBoolean\n\n</td><td>\n\nFlag that indicates whether the query contains a text query parameter.Valid values:\n\n-   true: Query contains a text query parameter.\n-   false: Query does not contain a text query parameter.\n\n</td></tr></tbody>\n</table>In the following example, the method returns true if the query contains a text query parameter, such as `GOTO123TEXTQUERY321=email`.\n\n```\nv_query.isTextSearch();\n```\n\n## v\\_query - setLastErrorMessage\\(String message\\)\n\nSets the last error message in the GlideRecord.\n\nSee also:\n\n-   [Scoped GlideRecord - getLastErrorMessage\\(\\)](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/c_GlideRecordScopedAPI.md)\n-   [Retrieving specific records from a third-party source](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/servicenow-platform/remote-table-script-def-example2.md)\n-   [v\\_table](https://raw.githubusercontent.com/ServiceNow/ServiceNowDocs/australia/markdown/australia/api-reference/server-api-reference/v_tableAPI.md) API\n\n|Name|Type|Description|\n|----|----|-----------|\n|message|String|Error message.|\n\n|Type|Description|\n|----|-----------|\n|None| |\n\nThe following example shows the basic structure used to set an error message.\n\n```\n(function executeQuery (v_table, v_query) {\n try {\n\n // Add code to test for errors during execution\n } catch(ex) {\n\n  v_query.setLastErrorMessage(ex.message);\n\n }\n\n}) (v_table, v_query);\n```\n\nThe following example shows how to set the last error message in a REST API.\n\n```\n(function executeQuery (v_table, v_query) { \n try {\n\n // call a REST API\n } catch(ex) {\n\n  v_query.setLastErrorMessage(\"Error obtaining results from remote service\");\n\n }\n\n}) (v_table, v_query);\n```\n\n"}}