- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2022 04:32 AM
※This is the Paris version.
I thought about deleting all the scripts created after 1 hour with the following script.
var time_difference =1000;
var nTime = new GlideDateTime();
nTime.addSeconds(-3600+time_difference); //1 hour ago
var grid_del = new GlideRecord(table_name);
grid_del.addQuery("sys_created_on", ">", nTime);
grid_del.query();
gs.info(grid_del.getRowCount());
grid_del.deleteMultiple();
However, the result of "grid_del.addQuery (" sys_created_on ","> ", nTime);" was not what I expected.
The timezone of the instance I'm currently using is other than "GMT".
When using ".addQuery (" sys_created_on ","> ", nTime);" in a script, is the time of "sys_created_on" a GMT value?
When I changed the time zone to GMT and executed it with "time_difference = 0", it was the expected behavior.
I'm in trouble because I can't understand how it works.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2022 04:57 AM
Hi,
internally in XML the sys_created_on value is stored in GMT.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2022 04:36 AM
Hi,
you want to check records created 1 hr ago from now?
var nTime = new GlideDateTime(); -> this is always in GMT
then do this
Before deleting print the count
var nTime = new GlideDateTime();
nTime.addSeconds(-3600); //1 hour ago
var grid_del = new GlideRecord(table_name);
grid_del.addQuery("sys_created_on", "<", nTime);
grid_del.query();
gs.info(grid_del.getRowCount());
//grid_del.deleteMultiple();
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2022 04:50 AM
Will the value set for "sys_created_on" be the GMT value even if the timezone is changed to something other than GMT?
I thought I needed to add the diff seconds in ".addSeconds".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2022 04:57 AM
Hi,
internally in XML the sys_created_on value is stored in GMT.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2022 05:46 AM
Thank you for answering!
I am convinced.