PowerShellservicenow

Tip: Retrieve servicenow incidents and cmdb records for given configuration item | Scripted REST API and PowerShell

In my last blog I explained basics of “Scripted REST API” – Now, let me show the simple trick to query all incidents and changes for the given configuration item. In my case CAR-3 is a CI which has one incident record and for our demo lets create a Scripted REST API to fetch required information.

Note: You can think about Database views for your environment. I will cover that in my upcoming blog.

Our goal is to achieve below output (2 incidents [Created for a demo] for given CI [CAR-3] and required CI field information)

System Definitions (Script Includes)

Scripted REST API

Now, comes our PowerShell code!

To get the full result as JSON use the below snippet.

Output

Summary : By implementing this we can avoid multiple web requests to servicenow instance. For example if we use OOB REST API we need to send web requests as illustrated below

  1. Query incident table.
  2. Query cmdb_ci table
    1. Send request(s) to get profile information which are masked as ID (Example managed_by , state etc)

 

Leave a Reply

Your email address will not be published. Required fields are marked *