Requirement: Our business is maintaining locations in third party server where they have millions of records, and they will be updating the parameters of those records every now and then, because of various developments. So, we had to access such data from there and must store only if it is needed and that must be a typeahead search.
Implementation: : ServiceNow have a brilliant feature called Remote tables, which are scriptable tables (hence their name contains “st” by default). The data here is not static but is completely dynamic i.e., the records it shows up here are results of scripting in the table definition. It is like an index page or an interface, it won’t store anything at ServiceNow it just displays the results of the scripting, usually we can script for other tables within ServiceNow connecting multiple tables for reporting or for various reasons.
We used the scripting feature of Remote table to integrate with third party server to retrieve the required records and add them as records as I type through each letter in our search.
We have implemented this in our PDI, and we had used another ServiceNow instance’s (another PDI)
location data for POC and to showcase it here.
Remote table Columns of it has been created whichever are needed as per requirement
Remote table definition
Remote table definition has its own API:
v_table – API to access the remote table to add JSON objects as rows or records to the list
v_query – API to access search queries we are sending to the table
Below is the snapshot of code implementation, one can configure it according to their requirements
As the results in this table can’t be accessed to retrieve the details individually, (as Remote Table is just an interface of results) we will be making the unique id of the records from third party as sys_id of the records at ServiceNow. In this case u_location_id is the unique id of the third-party data record.
Reference External Location field at ServiceNow will be referred to the Remote Table created above, and its dictionary will be configured to allow auto complete making it as a Typeahead search.
External Location ID field will be set with sys_id of the selection the user makes from the search results using client script (usual onChange client script) and it will be saved.
We then can make use of this ID to fetch the results of the individual record using a business rule.
Summary:
Here’s how it works whenever we search for something in the table our search query will be accessed by Script with the help of v_query , it refreshes for every character we type. Then in the Remote Table definition, the search query will be parsed as required and would be set in the REST API call, we make which would fetch the results. The results will be parsed again to add the records to the Remote Table list using v_table.
Following road map and gif explains the roadmap of functionality and actual user experience