sabell2012
Mega Sage
Mega Sage

NOTE: MY POSTINGS REFLECT MY OWN VIEWS AND DO NOT NECESSARILY REPRESENT THE VIEWS OF MY EMPLOYER, ACCENTURE.

 

DIFFICULTY LEVEL: INTERMEDIATE
Assumes a good knowledge and/or familiarity of ServiceNow Web Services and Scripting in ServiceNow. Assumes having taken the class SSNF and has good intermediate level of knowledge and/or familiarity with Scripting in ServiceNow. 


For a while I have been contemplating a series of articles on how to interface externally with ServiceNow using Scripted Web Services. In this first article I will be showing how to use a SOAP client to talk with a ServiceNow WSDL.      

 

Soap Client: SoapUI

 

I have been using SoapUI for almost as long as it has been around. I was looking for a decent Soap client tool and it was recommended to me by a friend. Since it is what I am most familiar with I will be using it in this example. Btw, in its latest couple of incarnations it does REST as well. Download from: SoapUI. Follow the installation instructions, and you will then be ready to walk through this short lab.

 

Disclaimer: This is not an endorsement of the SoapUI product by Accenture or myself. This is simply an example of how to test ServiceNow SOAP/WSDL using this tool.

 

Other SOAP Client tools to consider:

That is just a sampling. There are a plethora of them available on the web!

 

 

Lab 1.1: Retrieving an Incident Record

 

So what is involved?  

 

  1. We must create a new web service user that will be used to access ServiceNow.
  2. Next we have to create a group that will have the correct permissions, and then assign our new user to the new group.
  3. We must verify access to the WSDL via our favorite browser.
  4. We then fire up SoapUI and create a new project to retrieve incidents.

 

Lab

 

  1. Navigate to User Administration -> Users.
  2. lick the New button.
  3. Fill out the form with the following:
    1. User ID: svcuser
    2. First name: svc
    3. Last name: user
    4. Password: pick your favorite
    5. Web Service Access Only: checked.
    6. Accept the default for all other fields.
    7. Click the Submit button to save your work.

4. Navigate to User Administration -> Groups.

5. Click on the New button.

6. Fill out the form with the following:

    1. Name: Web Services
    2. Description: Contains users used by web services
    3. Right-click on the form header to display the context menu and Save.
    4. Scroll to the bottom of the form to the Related Links tabs, and click on the Roles tab.
    5. Click the Edit button.
    6. Add the following Roles:
      1. Itil
      2. Soap
      3. Click the Save button to save your work.

The Soap role allows our web user to access everything. We have to add the Itil role to be able to access and read Incident, Problem, and Change.  

g. Click on the Group Members tab, and click the Edit button.

h. Add the following User:

i. svcuser

ii. Click on the Save button to save your work.

 

You will see a series of blue informational messages showing that the itil and soap roles have been assigned to your user.

 

And we are done with the ServiceNow configuration side. We are all set to start doing queries from our external SOAP Client!

 

7. Open a new Tab in your browser, and enter your instance's url, remove /navpage.do, and tack on: /incident.do?wsdl. The url should look something like this:

    1. https://dev00000.service-now.com/incident.do?wsdl  <- where dev0000 is your PDI name
    2. Hit enter to view the Incident table's WSDL.

NOTE

ServiceNow out-of-the-box exposes most table's wsdl. This includes several commands with fields that can be utilized.   We will be focusing on the getRecords command.   You can find this by scrolling down a ways, and will look something like this:

 

sabell2012_0-1704051696956.png

 

WSDL commands allow and authorized SOAP Client to perform actions against the given table.

 

8. Now open up SoapUI.

9. Right-Click on Project to display the context menu, and click on New SOAP Project.

 

sabell2012_1-1704051828272.png

 

10. Fill out the form with the following:

a. Project Name: Incident

b. Initial WSDL: Fill in your incident WSDL url here.

Example: https://dev00000.service-now.com/incident.do?wsdl

c. Create Requests: Checked

d. Click the Ok button to display the Basic Authentication form.

sabell2012_2-1704052045224.png

 

11. The Basic Authentication form will appear.

12. Fill out the form with your new user credentials.

    1. Username: svcuser
    2. Password: your user's password.
    3. Click on the Ok button to create the new Incident project.

sabell2012_3-1704052130170.png

 

NOTE

If you get an error then try a couple more times. If it still fails you may need to exit Soap UI and retry. I've bumped into this a couple of times. Not sure why. Perseverance rules!

 

13. Soap UI does all the work for us by creating a new project with all of the commands, and the base XML we can use to submit our queries!

14. Navigate to Projects -> Incident -> ServiceNowSoap -> getRecords and expand the plus ("+") symbol. Select on Result1 which will be displayed. This will show the properties window below.

 

sabell2012_4-1704053396267.png

 

16. Fill out the properties window with the following:

  1. Name: getIncidents
  2. Username: svcuser
  3. Password: your user's password.

 

NOTE

It is necessary to re-fill in the user name and password for each command even though we entered it once already to create the project.   Soap UI does not assume the user name and password used to create the project will be the same used to do the queries.

 

sabell2012_5-1704053448935.png

 

17. Double-click on getIncidents to bring up the default XML and results window.  

 

sabell2012_6-1704053498942.png

 

NOTE
The XML displayed is just a template, and will not retrieve anything "as-is".   We will need to modify it in order to actually do a query.

 

18. Copy the XML out to your favorite editor (to keep it around).

19. From you instance grab an Incident record number. We will be pulling that record from SoapUI. I used INC0000049 for example.

20. Change the XML to something like the following:

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:inc="http://www.service-now.com/incident">
    <soapenv:Header/>
    <soapenv:Body>
            <inc:getRecords>
                    <number>INC0000049</number>
            </inc:getRecords>
    </soapenv:Body>
</soapenv:Envelope>

 

NOTE If you have a lot of incidents you may want to use additional fields to narrow the search. Each parameter you add will be ANDed to the previous.

 

21. Click on the Start (green) button in the upper left corner of the XML form. This will run our query. After a few seconds the results will appear in the right side (results panel).

22. Copy out the very last line and paste it into your favorite editor (hopefully one that can format XML).

 

sabell2012_0-1704069970964.png

 

In my editor:

 

sabell2012_1-1704070085909.png

 

23. Scroll through the results to verify that the correct record was returned.

 

sabell2012_2-1704070111744.png

 

And there you go! You can start playing around with the SOAP query in SoapUI and pull back multiple records if you want.

 

A good reference for ServiceNow SOAP and WSDL can be found here in the SOAP web service .

 

And that is all there is to it! This completes the set-up of our testing environment for SOAP queries.

 

Enjoy!

Steven Bell.

 

If you find this article helps you, don't forget to log in and mark it as "Helpful"!

 

sabell2012_0-1703972921222.png


Originally published on: 11-23-2015 11:27 PM

I updated the code, fixed broken links, and brought the article into alignment with my new formatting standard.

9 Comments