Snow-Shell/servicenow-powershell

Warning when using -Limit in Get-ServiceNowTable

Closed this issue · 5 comments

First, thanks for putting this together as it has been immensely helpful.

When calling Get-ServiceNowTable I want to get all records in the table so am using -Limit with a high number. But when I do that I get a warning about it being deprecated and to use -First instead, however that parameter is not yet available. Has it just not yet been implemented?

Thanks, Bruce...

Hey Bruce. If you are determining that it hasn't been implemented by not seeing it as a parameter, that's because it's automatically added when using the cmdletbinding attribute 'SupportsPaging'. You can see where it's used on line 92 currently in the master branch.

Get-Command Get-ServiceNowTable -Syntax shows you that -First is an available parameter. Otherwise it's not listed in the help because, as stated in the previous comment, it's an automatically added attribute by means of 'SupportsPaging'.

It's still on the to-do list to improve the help across the board. I'll see about how to document the SupportsPaging features. Probably about time to redo the GitHub ReadMe to clean out the older data and improve on stuff like this.

So if I want to return the maximum number of rows possible then I use -First without any value, per the comment on line 84? I was confused because I thought -First referred to the first record number I want returned, e.g. to use in paging. Thanks, Bruce...

The parameters work like they do with Select-Object. You can play with 1..14 | Select-Object -First 10 -Skip 3 as an example. That line will skip 1-3, and return 4-13 (ten objects) leaving 14 out all together.

First defaults to a value of [uint64]::MaxValue if you don't call First at all as default behavior, which is what that comment describes. The function however overrides that behavior and defaults to a value of 10. Basically if you want everything you should pass a number that is big enough for your environment without being the max value for uint64.

That said I'm getting really whack behavior out of my environment whether I use First or Limit. Wildly different results each time (not just going up because of increased traffic). Seems to be when I try to get "everything". Not sure if it's just my tenant or something with the API. Interested to get feedback on what you experience.

I've had this same issue and it was due to the number of records being retrieved at one time. Now that paging has been implemented, #133, this shouldn't be an issue any longer. To retrieve all records, use -First xx -IncludeTotalCount where xx is the number of records to retrieve with each call. If you find this behavior persists, lower the value for -First until it goes away.