Use Last Run Datetime for a JDBC type data source
There has been some questions in forum about using "Use Last Run Datetime" field so I have attempted here to explain it a bit more than what is there in the wiki. The checkbox appears when the type of the data source is JDBC. And if you were to select the checkbox you will see additional two input fields, Last run datetime and Last run database field as shown below in the screenshot.
Last run database field is the column in the source table that you would like to compare on an ongoing basis. It is not the column in your import table but the exact column name in your data base.
So say you have a table which is getting populated on a daily basis and you would like to fetch the delta records by just obtaining the delta from the last time you fetched it -
In order to do that, you can point to the table and leave the Last run datetime field empty. Before we proceed further, I would like to mention that there is a business rule "Format last run datetime" on the data source table. We can edit this business rule in case we feel that the date format of the incoming data source has to be formatted. I would generally leave this field unedited.
So once you have taken the initial load, ServiceNow automatically populates the Last run datatime after the import with the date value of the column. We don't have to specifically fill this field. When your next job runs it executes a sql statement to compare the load date in your source database against the last run date time field.
Something like
Select * from tableName where load_date >= value from last run date time field.
Note: Since it is greater than equal to operator it would pull the current listed date on last run date time values as well apart from later dates.
If you want the delta to start from a specific date we can do a manual entry into the Last run datetime field as well.
This ensures that we keep fetching the data on a delta basis and do not have to get the full table load. I would like to mention that your sql query cannot have where or any condition if you are using the last run date time field. It should just be a select * from tableName so I would suggest creating a view that has all your records for fulfilling your requirements.
https://www.servicenow.com/community/developer-articles/use-last-run-datetime-for-a-jdbc-type-data-source/ta-p/2313070