Most people are probably aware of the ability of a ServiceNow instance to export data into different file formats using a RESTful “GET” call to the instance. In essence, you specify the table_name.do and tack on a format identifier and “voila!” a file is downloaded to your computer with data from the instance.
For information on the various web services that can do this, and how each one behaves, check out the following wiki articles:
- CSV Web Service
- EXCEL Web Service
- XML Web Service
- JSON Web Service
- RSS Feed Generator
- PDF Web Service
There have been a few times when it would be helpful to have a Runbook/Orchestration activity that would allow my workflow to deliver a data export file to a machine either on a scheduled basis or part of a designed process. CrossFuze Solutions, offers a scheduled data extract, which is very handy. While this method has a similar outcome, the use case is geared for an Orchestration script.
This activity is based off of the Powershell runbook libraries and thus requires a windows computer. Linux computers are easier as you can just use a simple “wget” command. However, given Powershell’s capabilities, this is doable with very little effort.
Once you upload this activity by loading the update set listed in this article, you can leverage it through the Workflow Editor application in ServiceNow. Simply browse to: “Runbook – PowerShell”->”Export SN Data Windows”. Drag that activity onto your workflow editor.
Here is a quick rundown on the fields:
- Hostname: The computer that will execute and store the export file. For the MID Server executing this, just use 127.0.0.1.
- Instance URL: The URL of the ServiceNow instance you will be exporting from
- ServiceNow User Name: The user account in ServiceNow that will do the authentication
- ServiceNow User Password: The ServiceNow user’s password
- Format: One of the supported export formats
- Resource: This is the ServiceNow table name, database view name, or report name (note, while all formats support the tables, they don’t all support views or reports – see the wiki documentation for each format.
- Query Paramters: A name value pair of URL query parameters for the request. Each pair should be on its own line.
- Output File: The location and name of the output file containing the export data.
To demonstrate this, I’ll show you how to enter workflow activities for the following scenario:
Get all Priority 1, Active Incidents into an XML file
- Hostname: 127.0.0.1 (I just want it to execute and store the file on the mid server itself)
- Format: XML
- Resource: incident
- Query Parameters: sysparm_query=active%3D1%5Epriority%3D1 (Notice how I need to URL Encode the query since it contains “=” signs.)
- Output File: c:\MIDServer\agent2\activeP1incidents.xml
Hey John, I am trying to use this activity and I am only getting back the following fault description:
Error: The remote server returned an error: (401) Unauthorized.
Is there something required on the Windows security side to get this to work?
@Darrin, this may mean you are not authenticating properly. Ensure that the user credentials you are using in the activity has proper credentials to grab that resource.
Hi John,
This Powershell activity is for Runbook, but in Orchestration plugin it is not present. Do you have any idea how i can achieve this..