mineshpatel
ServiceNow Employee
ServiceNow Employee

The ability to describe sets of data in JSON format is a natural extension to the JavaScript language. ServiceNow supports a web service interface that operates on the JSON object as the data input and output format. It is a web service provided by a platform-level processor similar to the services for SOAP, WSDL, CSV, Excel, and XML. Like those services, the JSON web service is triggered by a standalone JSONv2 URL parameter.

For example:

https://<instance name>.service-now.com/mytable.do?JSONv2

Having the JSON object available as a data format for web services means that you can create (insert), update, and query any data in the ServiceNow platform using the JSON object format, and get results in the JSON object format. The ability to do so is available in all instances starting with the Dublin release. When executing a JSONv2 request to retrieve data from a table, by default it will return all the fields associated with the record.

Limiting fields that you want to see using a JSONv2 call

Sometimes there are many fields that we do not care about and do not want to be a part of the data retrieved. You can avoid including unwanted data by using the Exclude Columns function and alternate it by using a view instead. This way you can limit fields that you want to see when making a JSONv2 call.


Example of limiting fields to view using JSONv2:

When we do the following we see all the fields associated to this record on the Incident table.


Example URL:

http://myinstance.service-now.com/incident.do?JSONv2&sysparm_sys_id=46edaa6aa9fe198101b9d14ced16619f

See example below,

Allrows.jpg

In the case that we only want to see two field values "Number" and "Short Description" of an Incident, we can create a view using a Database View.

To create a Database View:

  1. Navigate to System Definition > Database Views.
  2. Click New.
  3. The Database View form appears.
  4. Name the view as you would name a new table.
  5. The Label and Plural fields define how the database view is labeled in lists and forms.

CreateDBView.jpg

Once you have created the database view, click on New from View tables

ViewTableCreate.jpg

This will allow you to add the fields that need to be viewed using the View Table.   For examples, let's add the Number and the Short Description.

AddFields.jpg

Once this is defined we should get the result as needed. This time we need to execute the query using the view   name "u_blog" instead of the base table name

Example URL:

http://myinstance.service-now.com/u_blog.do?JSONv2&sysparm_sys_id=bcf0c1972b3631006c59ae6219da15a0


This should only return the two values as needed.

RestClientTwoReturned.jpg

From this post you have now learned how to limit fiends to a view using JSONv2, create a database view with the short description and the number available, and execute the query. For more information on creating, administrating, switching and deleting views, see View management - form views.

2 Comments