python-servicenow icon indicating copy to clipboard operation
python-servicenow copied to clipboard

Querying Partial Info with fetch_all or fetch_one using "Contains" or "LIKE"

Open dfields186 opened this issue 6 years ago • 0 comments

I'm trying to figure out how to query a table in servicenow using either the "fetch_all" or "fetch_one" methods and use a "contains" like construct so that if I query for a street address I can just put in an address like '1234 Some Street' or I could I put in '1234 Some' and I would all the records with street names matching '1234 Some' - in case there were records with the abbreviation 'St' or 'Str', etc.

partial code listing below:

import pprint sn_cmn_location = ServiceNow.Base(sn_conn) sn_cmn_location.table = "cmn_location.do" street = input("Street Address: ") results = sn_cmn_location.fetch_all({'street': street}) if len(results['records']) > 0: print("Records found: " + str(len(results['records'])))

    for record in results['records']:
        try:
            if record['__status'] == 'success':
                print("Incident Location: " + record['name'])
                pprint.pprint(record)

        except KeyError:
            print("Record not Found")
else:
    print("Zero records found")

dfields186 avatar Oct 29 '19 12:10 dfields186