Snow-Shell / servicenow-powershell

PowerShell module to automate ServiceNow service and asset management. This module can be used standalone, with Azure Automation, or Docker.
Apache License 2.0
359 stars 170 forks source link

Get-ServiceNowRecord -Filter not functioning as expected #183

Closed ajacks88 closed 2 years ago

ajacks88 commented 2 years ago

Apologies if this is something simple, i had been using your module back when Get-ServiceNowTable was a thing and it worked great. I am attempting to update my scripts to use the new Get-ServiceNowRecord but am having some trouble. Here is what im running (after authenticating)

Get-ServiceNowRecord -table cmdb_ci_server -Filter @('name', '-eq', 'someservername')

However, what i get back from this cmdlet is 10 server records, all of which have no name at all.

Am i missing something?

What i used to run was : Get-ServiceNowTable -Table cmdb_ci_server -Query "name=$servername" and it worked like a charm.

gdbarron commented 2 years ago

I just tried the same command and worked for me. What version of the module are you using? What version of powershell? Can you run with -verbose and provide output please? All the details on the bug report issue would be helpful.

wwwb0n3zcom commented 2 years ago

I'm getting the same problem using v3.1.9

Example: Get-ServiceNowRecord -Table 'Change Request' -Filter @('assigned_to', '-eq', 'Kenneth Jones')

Or using: Get-ServiceNowRecord -Table 'Change Request' -Filter @('assigned_to', '-like', 'Kenneth Jones')

It responds with 10 RFC (not even CHG tickets) and none of these are assigned to Kenneth Jones.

gdbarron commented 2 years ago

I found the issue and will be fixing it shortly. The issue was with the filter not applying correctly in certain circumstances.

@wwwb0n3zcom, while there is an issue with the filter not applying, there is also an issue with how you are calling the filter. assigned_to is a reference field and you must either provide the sys_id to compare against or dot-walk if you want to compare against a field in the reference. See the example:

image