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
360 stars 170 forks source link

Match arguments seem to be ignored #45

Closed ghost closed 5 years ago

ghost commented 6 years ago

Have tried:

Get-ServiceNowIncident -ServiceNowCredential $Creds -ServiceNowURL xxxxxxxxxxxxxxxxx.service-now.com -MatchExact @{Number="INC9999999"}

and

Get-ServiceNowConfigurationItem -ServiceNowCredential $Creds -ServiceNowURL xxxxxxxxxxxxxxxxxxx.service-now.com -MatchExact @{Name="anynameyouwanttotry"}

but all I ever get back is last 10 created items (in this case, incident and CI). It does not care about -MatchExact or -MatchContains

Anyone else run into this?

ghost commented 6 years ago

When I ran debug on this line: Get-ServiceNowConfigurationItem -ServiceNowCredential (get-credential xxxxxxxxxx) -ServiceNowURL 'xxxxxxxxx.service-now.com' -MatchExact @{Name="garbage"}

the sysparm_query argument which I assume SNOW uses was equal to:

ORDERBYDESCname^Name=garbage

In the examples I have seen on SN web site, ORDERBY is listed at the end?

Rick-2CA commented 6 years ago

I was able to reproduce your issue. The property name in the REST call is case sensitive. It looks like we should be able to easily force lower case on the field property in New-ServiceNowQuery to remove case sensitivity from the module users.

If my SNow admins don't think it's a bad approach and nobody else comments on the issue I'll work this into the dev branch.

ghost commented 6 years ago

Is there a workaround until?

Rick-2CA commented 6 years ago

Instead of -MatchExact @{Number="INC9999999"} do -MatchExact @{number="INC9999999"}. Specifically "number' should be in lower case when you type the command.

gdbarron commented 5 years ago

@Rick-2CA, I have code updates ready if you've confirmed we can set the keys to lowercase without issue.

gdbarron commented 5 years ago

I was testing the code change and came across something odd. Not only is the property name case sensitive, but if you mistype the property it still comes back with the default 10 results. In looking at the SN docs this is due to a setting:

If part of the query is invalid, such as by specifying an invalid field name, the instance ignores the invalid part. It then returns rows using only the valid portion of the query. You can control this behavior using the property glide.invalid_query.returns_no_rows. Set this property to true to return no rows on an invalid query.

Here's how you set that value on your instance. I've tested this and although it works, you get a 404 Not Found if no rows are returned so we'd need to handle that.

With this in mind, I think we should still move forward with changing the property names to lowercase, but feel we need to do something more to make this more intuitive.

Rick-2CA commented 5 years ago

Share away. Either submit a PR or commit the changes to your fork and let me know.

I've run into that behavior before. We'd probably have to do something like check to make sure every property name submitted shows up in the results. If it doesn't we presume it was an invalid query and throw away the results. Perhaps worth an issue on the topic for future consideration.