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

Not able to retrieve all rows from a table. #170

Closed CrazyMonkeyCode closed 2 years ago

CrazyMonkeyCode commented 2 years ago

Environment

ServiceNow Rome Patch 3 Hotfix 1

Operating System: Win10
ServiceNow module version: 3.1.3 (same problem with 3.1.2)
PowerShell version: 7.2 Core

Steps to reproduce

Get-ServiceNowRecord -Table "cmdb_ci_service" -Connection $ServiceNowProdSession -IncludeTotalCount

WARNING: Getting 4416 records... Write-Error: C:\Users\%PATH%\PowerShell\Modules\ServiceNow\3.1.3\Public\Get-ServiceNowRecord.ps1:292:15 Line | 292 | $result = Invoke-ServiceNowRestMethod @invokeParams | ~~~~~~~~~ | The expected number of records was not received. This can occur if your -First value, how many records retrieved at once, is too large. Lower this value and try again. Received: 1425, expected: 4416

Expected behavior

All records returned.

Actual behavior

Not sure if the problem is ServiceNow or the module. My script was working fine until the upgrade of ServiceNow. I could retrieve all record by specifying "-IncludeTotalCount" with the Get-ServiceNowRecord cmdlet

For some reason it only returns 134 or 1425 record (See picture) if I ask for more than 134 rows. Combining "-IncludeTotalCount" and "-First" doesn't change the number of items returned.

Using Postman returns expected amount of rows.

Created a developer instance of ServiceNow(same version as mentioned here) to see if I could reproduce the issue. Added 4500 dummy record in the table and tried to get them all. Worked.

Screenshots

image

CrazyMonkeyCode commented 2 years ago

Not related to module. Combination of permissions and timeout.