Is there any API to get the List of tables present in ServiceNow?

rna
Kilo Explorer

Is there any SOAP or REST api which can get the list of tables Both standard and custom tables present in serviceNow?

1 ACCEPTED SOLUTION

emir_e_eminovic
Giga Contributor

sys_db_object_list



From the left navigation pane, select System Definition > Tables and Columns. Click tables


Name has all the tables/views.



Tables & views has th elist and a schema. use .list to view it remotely.


View solution in original post

8 REPLIES 8

Hi Rohit,



Consider marking the question as answered, or marking replies as helpful as appropriate.


Or ask further questions or tell us what solution you found.


This will add value to Community Members reading this thread.



Best Regards



Tony


tony_barratt
ServiceNow Employee
ServiceNow Employee

Hi Rohit,



Consider marking the question as answered, or marking replies as helpful as appropriate.


Or ask further questions or tell us what solution you found.


This will add value to Community Members reading this thread.



Best Regards



Tony


emir_e_eminovic
Giga Contributor

sys_db_object_list



From the left navigation pane, select System Definition > Tables and Columns. Click tables


Name has all the tables/views.



Tables & views has th elist and a schema. use .list to view it remotely.


johnlbevan
Kilo Contributor

Here's a solution using PowerShell to automatically pull back a list of all tables:



Get a list of all tables in ServiceNow using PowerShell and the SOAP API. · GitHub


function ConvertTo-SecureCredential {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [string]$username
        ,
        [Parameter(Mandatory)]
        [string]$password
    )
    process {
            $pass = ConvertTo-SecureString $password -AsPlainText -Force
            New-Object System.Management.Automation.PSCredential ($username, $pass)
    }
}
Function Get-SnRecord {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [string]$InstanceName
        ,
        [Parameter(Mandatory)]
        [System.Management.Automation.Credential()]
        [PSCredential]$Credential = [System.Management.Automation.PSCredential]::Empty
        ,
        [Parameter(Mandatory)]
        [string]$TableName
        ,
        [Parameter(ValueFromPipeline)]
        [hashtable]$Filter = @{}
    )
    begin {
        #http://wiki.servicenow.com/index.php?title=SOAP_Direct_Web_Service_API#gsc.tab=0
        $proxy = New-WebServiceProxy -Uri ('https://{0}.service-now.com/{1}.do?wsdl' -f $InstanceName, $TableName) -Credential $Credential
  }
    process {
        $proxy.GetRecords($Filter)
    }
    end {
        $proxy.Dispose()
    }
}
    clear-host
    $snDefaultLimit = 250 #this is the SN default limit; including in a variable so it's easy to change should this ever be amended server side
    $snInstance = 'myCompany' #CHANGE THIS: use value from your SN instance's URL https://myCompany.service-now.com/
    $snTable = 'sys_db_object_list' #table holding a list of table names
    $snFilter = @{'__order_by'='name'} #order by https://wiki.servicenow.com/?title=Direct_Web_Services#gsc.tab=0
    [PSCredential]$snCredentials = ConvertTo-SecureCredential -username 'mySnSoapAccount' -password 'myPassword'   #CHANGE THIS: use `Get-Credential` to prompt, `[System.Management.Automation.PSCredential]::Empty` to use your current Windows/AD credentials, or replace the username and password parameters to use a dedicated SN account's credentials.
    [psobject[]]$tables = @()
    [boolean]$hasMoreData = $true
    while ($hasMoreData) {
        $snFilter.'__first_row' = $tables.Count #first, last and limit values also documented here: https://wiki.servicenow.com/?title=Direct_Web_Services#gsc.tab=0
        $snFilter.'__last_row' = $tables.Count + $snDefaultLimit
        $snFilter.'__limit' = $snDefaultLimit
        write-verbose "Getting next $snDefaultLimit rows, starting at $($tables.Count)" -Verbose #added the -verbose switch here whilst testing so this always happens, even when invoking from R5 in IDE
        [psobject[]]$newResults = Get-SNRecord -instanceName $snInstance -tableName $snTable -Credential $snCredentials -filter $snFilter | select sys_id, name #for now just return basic columns for ease
        $tables = $tables + $newResults
        $hasMoreData = ($newResults.Count -eq $snDefaultLimit)
    }
    "$($tables.Count) tables were returned"
    "$(($tables | select sys_id -unique).Count) unique tables were returned; if this doesn't match the above; we've somehow read the same row twice :S"
    $tables | Format-Table sys_id, name #list off all tables fetched; should be listed alphabetically due to our order by clause