Fetch only updated records from Table API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2024 11:45 PM
We have a integration request where, on first call it will fetch entire table records but from next request it should only fetch updated records since last request
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 12:03 AM
Hi @Priyanka Palask ,
First Request - All records are fetched (assume it to be 100).
I am assuming you are storing logs for requests & responses in the custom API logging table.
Second Request - You need only updated ones after the pervious request. You can access the GlideRecord object of the logging table & fetch the created date. Now based on that created date, return the records which have higher value in sys_updated_on ( Target Table ) than the created date ( API log table ).
Please mark this helpful, if this answer solves your concern.
WR,
Uday
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 12:32 AM
Hi
To Fetch only updated records from Table API, Please follow this steps.
At First open Rest API Explorer and configure API Name to Table API and select required table to fetch records.
fill required fields as per Requirements and Now click on send button to fetch entire table Records.
after fetching records create another Request with (GET) value and open Required Table in another tab. in that Table create a Query as " Updated =on=Last minute/current minute" and Run the Query. the records are displayed as per the Query. Copy the Query URL and paste it in the "sysparm_query" field and click on send button. Here You can see Last updated Records.
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 01:57 AM
Hi @Priyanka Palask ,
You can add a last_fetch_date date time field to the table and then you can compare the last updated date with last_fetch_date to find the last updated records.
If my post helped you, please click the accept solution button and hit the thumbs up! Thank you!
Oya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-16-2024 02:24 AM
Sure, you can achieve this by using the 'sys_updated_on' field in ServiceNow. This field stores the timestamp of when a record was last updated. You can use this field to fetch only the records that have been updated since your last request.
Here are the steps to implement this:
1. Create a variable to store the timestamp of the last request. This could be a system property or a record in a custom table.
2. On the first request, fetch all records from the table and store the current timestamp in the variable.
3. On subsequent requests, fetch only the records where 'sys_updated_on' is greater than the stored timestamp. This will give you only the records that have been updated since the last request.
4. After each request, update the stored timestamp with the current time.
Here is a sample script to illustrate this:
javascript
// Get the stored timestamp
var lastRequestTime = gs.getProperty('last_request_time');
// If this is the first request, fetch all records
if (!lastRequestTime) {
var gr = new GlideRecord('your_table');
gr.query();
while (gr.next()) {
// Process the record
}
} else {
// Fetch only the records updated since the last request
var gr = new GlideRecord('your_table');
gr.addEncodedQuery('sys_updated_on>=javascript:gs.dateGenerate("' + lastRequestTime + '")');
gr.query();
while (gr.next()) {
// Process the record
}
}
// Update the stored timestamp
gs.setProperty('last_request_time', gs.nowDateTime());
Please replace 'your_table' with the actual table name you are working with.
nowKB.com