Closed ghost closed 5 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?
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.
Is there a workaround until?
Instead of -MatchExact @{Number="INC9999999"}
do -MatchExact @{number="INC9999999"}
. Specifically "number' should be in lower case when you type the command.
@Rick-2CA, I have code updates ready if you've confirmed we can set the keys to lowercase without issue.
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.
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.
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?