ServiceNow GlideRecord sysparm_query Python

1.2k views Asked by At

Has anyone used the GlideRecord library for python? I can't seem to get it to perform some fairly basic functionality. I want to add a few sysparm_query parameters. This is just a code snippet, I had to manually edit it for security purposes. Hopefully I didn't introduce any typo errors.

for i in glide1, glide2:
    i.set_credentials('xxxx', 'xxxx')
    i.set_server("https://<instance>.service-now.com/")
    i.addQuery("active", "true")

def getIncidents(glide1):
    group = "mygroup"
    glide1.addQuery('assignment_group', group)

    print glide1.query_data['sysparm_query'] + '\n'
    print glide1.getQuery()[50:] #just to avoid too much output

gives me the output:

active=true^assignment_group=mygroup

displayvalue=true&JSONv2&sysparm_record_count=100&sysparm_action=getRecords&sysparm_query=

I cannot get the query data to append. Perhaps I should look at doing the queries manually? Here is a link to the GlideRecord git:

https://github.com/bazizi/ServiceNow_GlideRecord_API/blob/master/GlideRecord/init.py

Cheers, Arthur

1

There are 1 answers

0
Behnam On

I just realized that the getQuery() member function I had defined only returned the base query URL (not including the query itself). I had initially added this function for testing purposes, and wrongfully added this to the documentation.

I just fixed this issue and committed to the GitHub repository. Please pull from the git repository again or if you installed using PIP, run the following commands to re-install it from scratch:

pip uninstall GlideRecord
pip install GlideRecord

In terms of setting the assignment group by name, however, I still need to find out how ServiceNow hashes the assignment_group, or if there is another way this query can be added; That is, I have no fix for now.

Thanks

Behnam