Trying to get data from service now to get all like wise server , can any one help me with query host_nameSTARTWITH that is having issues


(sun_deep) #1
class GetNonStructuredAction(BaseAction):
    def run(self, table, name, dev=False):

        default_payload = None
        try:
            self.get_client_with_default_payload(default_payload,dev)
        except Exception as err:
            return (False, err)

        names = [name]
        s = self.client
        for name in names:

            query = {"name": name}
            r = s.query(table=table, query=str(host_nameSTARTSWITH{{query}}))  # pylint: disable=no-member
            response = r.get_multiple()  # pylint: disable=no-member
            output = []
        for each_item in response:
            output.append(each_item)
        return output

(Lindsay Hill) #2

Could you explain a bit more about what you’re doing here? Are you writing a new action for the Service Now pack?

What are issues that you have? Maybe explain a bit more about the command you’re running, the output that you’re getting, and how that differs from what you expect?


(sun_deep) #3

Im writing a new action in service now pack to get the list of servers that were having name that starts with similar words. so the service now query is u_active=true^nameSTARTSWITHservername


(Lindsay Hill) #4

And what results are you getting? What is not working?


(sun_deep) #5
 File "/opt/stackstorm/virtualenvs/servicenow/lib/python2.7/site-packages/pysnow/request.py", line 88, in _all_inner
    yield self._get_content(response)
  File "/opt/stackstorm/virtualenvs/servicenow/lib/python2.7/site-packages/pysnow/request.py", line 316, in _get_content
    raise NoResults('Query yielded no results')
pysnow.exceptions.NoResults: Query yielded no results

(Lindsay Hill) #6

What results do you expect to see? You haven’t said what your query was, and we have no idea what data you have in your ServiceNow system. So what results do you expect to get back?

What happens if you try using a simple Python script that uses the pysnow library to run your query? Does that work? What about just making manual curl calls against the API? Can you get it to return what you expect?

Break the problem down to the smallest parts, and look at those.