<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Re: Getting all records from a table in Developer forum</title>
    <link>https://www.servicenow.com/community/developer-forum/getting-all-records-from-a-table/m-p/2779663#M1068596</link>
    <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/20651"&gt;@mhashemi&lt;/a&gt;&amp;nbsp;:&amp;nbsp;As the record count is high, we should be handling these calls with&amp;nbsp;&lt;STRONG&gt;sysparm_limit&amp;nbsp;&lt;/STRONG&gt;and&amp;nbsp;&lt;STRONG&gt;sysparm_offset&lt;/STRONG&gt;&amp;nbsp;in the API. Please refer to the HI articles below that explain in detail the issue and the implementation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.servicenow.com/kb?id=kb_article_view&amp;amp;sysparm_article=KB0727636" target="_blank" rel="noopener"&gt;https://support.servicenow.com/kb?id=kb_article_view&amp;amp;sysparm_article=KB0727636&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;Similar Issue Article:&amp;nbsp;&lt;A href="https://www.servicenow.com/community/developer-forum/need-to-understand-quot-sysparm-limit-and-sysparm-offset-quot-in/m-p/2243152" target="_blank" rel="noopener"&gt;https://www.servicenow.com/community/developer-forum/need-to-understand-quot-sysparm-limit-and-sysparm-offset-quot-in/m-p/2243152&lt;/A&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;Please mark this as&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;correct answer and helpful&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;if it resolved, or mark this&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;helpful&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;if this help you to reach towards solution.&lt;/SPAN&gt;&lt;/DIV&gt;</description>
    <pubDate>Wed, 03 Jan 2024 22:32:40 GMT</pubDate>
    <dc:creator>Sainath N</dc:creator>
    <dc:date>2024-01-03T22:32:40Z</dc:date>
    <item>
      <title>Getting all records from a table</title>
      <link>https://www.servicenow.com/community/developer-forum/getting-all-records-from-a-table/m-p/2779650#M1068593</link>
      <description>&lt;P&gt;I am trying to get all records from the customer_contact table, using the Table API. I am only getting 6-10k records (out of about 40k) before the command times out:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;"error": {
    "message":"Transaction cancelled: maximum execution time exceeded","detail":"maximum execution time exceeded Check logs for error trace or enable glide.rest.debug property to verify REST request processing"
}&lt;/LI-CODE&gt;&lt;P&gt;I have a meeting with one of our platform admins to discuss the timeout, but I wonder if there is another way I should be approaching this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For the record, I am using PowerShell to retrieve the records:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;$ServiceNowCredential = Get-Credential
$userTableName = 'customer_account'
$ServiceNowCompany = '&amp;lt;account sys_id&amp;gt;'
$snowUsers = [System.Collections.Generic.List[PSObject]]::new()
$webClient.Headers = $null
$webClient.Headers.Add('Authorization', ('Basic {0}' -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $ServiceNowCredential.UserName, [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($ServiceNowCredential.Password)))))))
$webClient.Headers.Add('Content-Type', 'application/json')
$webClient.Headers.Add('Accept', 'application/json')
$response = $webClient.DownloadString("https://&amp;lt;instance&amp;gt;.service-now.com/api/now/table/$userTableName`?sysparm_query=company%3D$ServiceNowCompany")

Foreach ($item in @($response | ConvertFrom-Json).result) { $snowUsers.Add($item) }&lt;/LI-CODE&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jan 2024 22:04:17 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getting-all-records-from-a-table/m-p/2779650#M1068593</guid>
      <dc:creator>mhashemi</dc:creator>
      <dc:date>2024-01-03T22:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: Getting all records from a table</title>
      <link>https://www.servicenow.com/community/developer-forum/getting-all-records-from-a-table/m-p/2779663#M1068596</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/20651"&gt;@mhashemi&lt;/a&gt;&amp;nbsp;:&amp;nbsp;As the record count is high, we should be handling these calls with&amp;nbsp;&lt;STRONG&gt;sysparm_limit&amp;nbsp;&lt;/STRONG&gt;and&amp;nbsp;&lt;STRONG&gt;sysparm_offset&lt;/STRONG&gt;&amp;nbsp;in the API. Please refer to the HI articles below that explain in detail the issue and the implementation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://support.servicenow.com/kb?id=kb_article_view&amp;amp;sysparm_article=KB0727636" target="_blank" rel="noopener"&gt;https://support.servicenow.com/kb?id=kb_article_view&amp;amp;sysparm_article=KB0727636&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class=""&gt;Similar Issue Article:&amp;nbsp;&lt;A href="https://www.servicenow.com/community/developer-forum/need-to-understand-quot-sysparm-limit-and-sysparm-offset-quot-in/m-p/2243152" target="_blank" rel="noopener"&gt;https://www.servicenow.com/community/developer-forum/need-to-understand-quot-sysparm-limit-and-sysparm-offset-quot-in/m-p/2243152&lt;/A&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;SPAN&gt;Please mark this as&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;correct answer and helpful&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;if it resolved, or mark this&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;helpful&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;if this help you to reach towards solution.&lt;/SPAN&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 03 Jan 2024 22:32:40 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getting-all-records-from-a-table/m-p/2779663#M1068596</guid>
      <dc:creator>Sainath N</dc:creator>
      <dc:date>2024-01-03T22:32:40Z</dc:date>
    </item>
    <item>
      <title>Re: Getting all records from a table</title>
      <link>https://www.servicenow.com/community/developer-forum/getting-all-records-from-a-table/m-p/2780758#M1068902</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/105247"&gt;@Sainath N&lt;/a&gt;, that seems like a useful solution, but is not working as expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With the following script, I am getting back 2486 records. It seems that ServiceNow is ignoring my 100-record limit:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;$ServiceNowCredential = Get-Credential
$userTableName = 'customer_account'
$ServiceNowCompany = '&amp;lt;account sys_id&amp;gt;'

$snowUsers = [System.Collections.Generic.List[PSObject]]::new()
$limit = 100
$offset = 0

Write-Host ('Limit = {0} and offset = {1}' -f $limit, $offset)

$webClient.Headers = $null
$webClient.Headers.Add('Authorization', ('Basic {0}' -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $ServiceNowCredential.UserName, [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($ServiceNowCredential.Password)))))))
$webClient.Headers.Add('Content-Type', 'application/json')
$webClient.Headers.Add('Accept', 'application/json')

write-host ('URL = {0}' -f "https://&amp;lt;instance&amp;gt;.service-now.com/api/now/table/$userTableName`?sysparam_limit=$limit&amp;amp;sysparam_offset=$offset&amp;amp;sysparm_query=company%3D$ServiceNowCompany")

$response = $webClient.DownloadString("https://&amp;lt;instance&amp;gt;.service-now.com/api/now/table/$userTableName`?sysparam_limit=$limit&amp;amp;sysparam_offset=$offset&amp;amp;sysparm_query=company%3D$ServiceNowCompany")

Foreach ($item in @($response | ConvertFrom-Json).result) { $snowUsers.Add($item) }

$snowUsers.count&lt;/LI-CODE&gt;&lt;P&gt;Since I am only running through the script once, I expect that $snowUsers.count would be 100, not&amp;nbsp;2486. Am I missing something?&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2024 15:00:52 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getting-all-records-from-a-table/m-p/2780758#M1068902</guid>
      <dc:creator>mhashemi</dc:creator>
      <dc:date>2024-01-04T15:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: Getting all records from a table</title>
      <link>https://www.servicenow.com/community/developer-forum/getting-all-records-from-a-table/m-p/2780784#M1068909</link>
      <description>&lt;P&gt;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/20651"&gt;@mhashemi&lt;/a&gt;&amp;nbsp;:&amp;nbsp;Looking into your PowerShell script that you pasted, I see the typo in sysparm. I see that you are using &lt;STRONG&gt;sysparam&lt;/STRONG&gt; instead of &lt;STRONG&gt;sysparm&lt;/STRONG&gt;. Please correct them and test it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="sainathnekkanti_0-1704381083476.png" style="width: 400px;"&gt;&lt;img src="https://www.servicenow.com/community/image/serverpage/image-id/317996i4646293F7C4F4EBE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="sainathnekkanti_0-1704381083476.png" alt="sainathnekkanti_0-1704381083476.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Please mark this as&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;correct answer and helpful&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;if it resolved, or mark this&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;helpful&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;if this help you to reach towards solution.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2024 15:12:12 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getting-all-records-from-a-table/m-p/2780784#M1068909</guid>
      <dc:creator>Sainath N</dc:creator>
      <dc:date>2024-01-04T15:12:12Z</dc:date>
    </item>
    <item>
      <title>Re: Getting all records from a table</title>
      <link>https://www.servicenow.com/community/developer-forum/getting-all-records-from-a-table/m-p/2780811#M1068916</link>
      <description>&lt;P&gt;Oops, found a typo. It is "sysparm", not "sysparam".&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2024 15:21:49 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getting-all-records-from-a-table/m-p/2780811#M1068916</guid>
      <dc:creator>mhashemi</dc:creator>
      <dc:date>2024-01-04T15:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: Getting all records from a table</title>
      <link>https://www.servicenow.com/community/developer-forum/getting-all-records-from-a-table/m-p/2780866#M1068927</link>
      <description>&lt;P&gt;For the record, since system.net.webclient is not returning any values in the response headers, I had to switch to Invoke-RestMethod in PowerShell 7 (which allows me to use the ResponseHeadersVariable parameter). Now I can do a loop to get all of the users:&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;$snowUsers = [System.Collections.Generic.List[PSObject]]::new()
$limit = 100
$offset = 0
$headers = @{
    'Authorization' = ('Basic {0}' -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $ServiceNowCredential.UserName, [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($ServiceNowCredential.Password))))))
    'Accept' = 'application/json'
    'Content-Type' = 'application/json'
}

Do {
    $response = Invoke-RestMethod -ResponseHeadersVariable responseHeaders -Uri "https://&amp;lt;instance&amp;gt;.service-now.com/api/now/table/$userTableName`?sysparm_limit=$limit&amp;amp;sysparm_offset=$offset&amp;amp;sysparm_query=company%3D$ServiceNowCompany" -Headers $headers -Method Get

    Foreach ($item in $response.result) { $snowUsers.Add($item) }

    $offset += $limit
} Until ($snowUsers.sys_id.Count -eq ($responseHeaders.'X-Total-Count' | Out-String))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Jan 2024 15:45:18 GMT</pubDate>
      <guid>https://www.servicenow.com/community/developer-forum/getting-all-records-from-a-table/m-p/2780866#M1068927</guid>
      <dc:creator>mhashemi</dc:creator>
      <dc:date>2024-01-04T15:45:18Z</dc:date>
    </item>
  </channel>
</rss>

