locaweb / python-servicenow

Python Library to interact and manage the ServiceNow database
Apache License 2.0
95 stars 47 forks source link

Retrieving multiple incidents using incident_list.do or by some other means #38

Closed dfields186 closed 5 years ago

dfields186 commented 5 years ago

I am wondering how to go about using incident_list.do using this library or some other method. I am trying to pull down a list of certain incident tickets using a particular query using the following:

assignment group incident state empty parent incident category

assignment_group=bf7d994a1346d780986cdd828144b07c ^incident_stateNOT IN6,7 # Not Resolved or Closed ^parent_incidentISEMPTY # Parent incident empty ^category=ATM # Category is ATM

The complete URL that ServiceNow uses is shown below and this works fine but I'm trying to write a python script using this library or the ServiceNow API to do the same thing:

https://myinstance.service-now.com/incident_list.do?sysparm_query=assignment_group%3Dbf7d994a1346d780986cdd828144b07c%5Eincident_stateNOT%20IN6%2C7%5Eparent_incidentISEMPTY%5Ecategory%3DATM

Any help is much appreciated thanks in advance!

dfields186 commented 5 years ago

So I figured out how to do this using Version v2.1.1 of this library using the following:

result = inc.fetch_all({'category': 'ATM', 'assignment_group': 'bf7d994a1346d780986cdd828144b07c', 'incident_state': ['2', '4', '100'], 'parent_incident': '', })

Works well and I can reference the individual records in the result, access various fields in each record, get the length of the entire result, as well as, iterate over the result, and print out the inc_number of each incident ticket obtained, using the following:

result_len = len(result['records']) for inc in range(result_len): inc_number = result['records'][inc]['number'] print(inc_number)

However, what I'm trying to figure out now is how to run the query by specifying incident states that are NOT certain values - is it possible to specify that for this fetch_all method?

For example, since I want to find all incidents which are NOT 6 (Not Resolved), NOT 7 (Not Closed), and NOT 8 (Not Ready to Close), how would I specify this in this search?

Example: result = inc.fetch_all({'category': 'ATM', 'assignment_group': 'bf7d994a1346d780986cdd828144b07c', 'incident_state': ['!6', '!7', '!8'], 'parent_incident': '', })

I've tried various different combinations, but can't seem to figure it out, so I thought I would ask the developers of this library.

Thanks much!

dfields186 commented 5 years ago

Never did figure out how to do this, so I just run the query with just the incident states needed, leave off the ones I don't want.