logo

NJP

Remote tables in Servicenow

Import · Oct 19, 2019 · article

I am sujan , new to communities but not to Servicenow image

Today we discuss about remote Tables in Servicenow , it’s a wonderful feature in Newyork version can be activated in personal Developer instance.

In this article we deal with a simple example to strengthen our understanding on remote tables

Activate Plugin :

Plugin: com.glide.script.vtable

image

New Application called System Definition > Remote Tables > Tables along with other artifact’s gets deployed .

You create remote tables to describe the schema for the data that you want to retrieve from an external source. The table definition is in the Now Platform, but its rows, or external records, live in the memory. You create a remote table the same way that you would create a standard internal table.

Remote tables gets its records from running an associated script using external data source.

By using a remote table, you can retrieve the data from external sources or from another instance with REST or SOAP services .

Refer the link for more details

Some of the use cases has been mentioned in the docs , however I see this concept has high potential usage with in the

>>Cloud Management Scope ( fetching the dynamics of the Cloud Datacentre Capacities and shown it to the cloud Catalog options

>> Ideally for maintaining the Token id’s we use for the integrations and storing temporarily , along with their validity.

Similar to system tables , but to identify a remote tables starts with u_st

image

The other difference I have observed that there is only sys field created when we create remote table i.e. sys_id

image

Remote tables gets its records from an associated script , we can only associate one script for one remote table

Create an Associate Scripts using System Definition >> Remote Tables >> Definitions

In the Caching section, designate how this data is cached and how long the data is cached in the memory of the Now Platform:

Goal is to get the currency values with the base as INR , upto date

image

Created associated script as follows

image

(function executeQuery(v_table, v_query) { // Main API: // v_table.addRow({ ... }) - adds a row to the result set // There are also query helper methods // v_query.getEncodedQuery() - returns encoded querystring // v_query.getCondition(field) - returns encoded querystring for the given field (includes field name, operator, and value) // v_query.getParameter(field) - returns parameter for the given field (only includes value for equality conditions) // v_query.isGet() - returns whether the query is a single get by sys_id // v_query.getSysId() - returns parameter for sys_id field // v_query.isTextSearch() - returns whether the query contains a text query parameter // v_query.getTextSearch() - returns text search query parameter (internal field name 123TEXTQUERY321) // v_query.getFirstRowWanted() - returns the first row to include // v_query.getLastRowWanted() - returns the last row to include // Note: You must define sys_id for each row so that forms and lists for this table work properly // Your code goes here // v_table.addRow({...}) fetchAllCurrencies(v_table, v_query); function fetchAllCurrencies(v_table, v_query) { var r = new sn_ws.RESTMessageV2('getCurrenciesValbyBaseLine', 'Default GET'); var response = r.execute(); var responseBody = response.getBody(); var httpStatus = response.getStatusCode(); if (response.haveError()) { v_query.setLastErrorMessage(response.getErrorMessage()); return; } var parsedRes = JSON.parse(responseBody); var actVal = parsedRes.rates; for (var k in actVal) { var row = {}; row["u_currency"] = k; row["u_valininr"] = actVal[k]; v_table.addRow(row); } } })(v_table, v_query);

The Cache TTL determines the refresh interval of the tables and also if a user access the table the data get automatically refreshes in the table , hence use sees the recent data

image

image

Will be posting more details about how to develop the script along with various artifacts in the next article

View original source

https://www.servicenow.com/community/developer-articles/remote-tables-in-servicenow/ta-p/2324967