Xurrent GraphQL - Filtering, Ordering and Views
Integrations GraphQL Training Finetune your Queries and Connections

Xurrent GraphQL - Filtering, Ordering and Views

When you want to browse through a list of records (for example Configuration Items) in the Xurrent UI, you will go to the records console and select the record type. In these views you have some options to finetune the list of records:

Configuration Items view in the Xurrent GUI

In the following exercises you will learn how you can do exactly the same with GraphQL API attributes that have been defined on the Connections objects.

Add a Filter and a Sort Order to a Connection

Let’s have a look at the fields that are available for the Root Connection object configuration items. Apart from the paging fields that we have been discussing in the previous topic some other arguments are available that make the UI functionality available: filter, order and view.

The syntax rules for defining multiple arguments with multiple fields are:

GraphQL - syntax to define arguments of a collection

In the following example the location filter is added to the Collection configurationItems. The filter excludes all configuration items that are linked to the list of locations. Because the field has multiple values, these values are defined between square brackets and because the locations are of type String the values are surrounded by double quotes.

GraphQL - syntax to define arguments of a collection

Exercises:

You will need to add view rights on the record type product to the scope of the personal access token. Add a filter productCategory with the value computer/desktop_pc_or_workstation to the GraphQL query on the products Collection.
Get of list of filtered and ordered configurtion items

This is the GraphQL query on the configurationItems Collection with filter and order arguments. You will need to perform 9 queries. By increasing the first attribute to 19 or more, you could reduce the number of queries.
Get of list of filtered and ordered configurtion items

Add a Query Filter to a Connection

In the records console of the Xurrent UI it is possible to enter keywords in the search bar to filter the list of records. In the ConfigurationItemFilter there is a query filter available which allows you to add a free format search string.

Exercise:

You just need to add the filter query: "Dell T5400" to the previous GraphQL query.
Get of list of filtered and ordered configuration items with a query string

Apply a View to a Connection

Finally the Xurrent GraphQL API allows you to specify a view to your query. In the next exercise you will apply the Spare CIs view. To make sure you get any results login as Howard Tanner to the Widget Data Center, go to the records console and select Configuration Items. Filter on the Dell T5400 product and set the status of at least one of these CIs to In stock.

Exercise:

Just add the attribute view: "Spare CIs" to the previous GraphQL query.
Get of list of configuration items based on a view

Remark: as explained on the Xurrent Developer Website there is a slight difference between a view in the user interface and a view in GraphQL. In GraphQL the view argument defaults to current_account when nothing is specified while in the user interface the view usually defaults to all.
You might check this behavior by creating a GraphQL query to count all active CIs in the Widget Data Center account without specifying the view argument. This will return a number that is less than what Howard Tanner gets in the user interface. Some configuration items that Howard Tanner gets in the ‘All Configuration Items’ view in the user interface belong to the Widget North America, IT account. To count also for configuration items that belong to another account you need to add the view: all argument to the GraphQL query.

Next Topic