- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2025 09:50 PM
I want to retrieve date and time of FREQ records when the status of FREQ changed to "Completed". I know I can retrieve it from sys_history_set and sys_history_line table. But the issue is I want this date and time for thousands of record and I couldn't find a way to do this in a bulk.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2025 10:03 PM
If your table is audited then you can do.
if you have a custom field to store then below sample script you can enhance for your table and field (date/time type)
I am giving example for incident table
if table is audited then you can do this
You can do GlideRecord from following tables,
sys_history_set and sys_history_line
For e.g. I am fetching history for incident number 'INC0010016' and getting when State changed to some value from empty
var incident = new GlideRecord('incident');
incident.addQuery('number','INC0010016');
incident.query();
while(incident.next()){
var history = new GlideRecord('sys_history_set');
history.addQuery('id',incident.getValue('sys_id'));
history.query();
history.next();
var auditH = new GlideRecord('sys_history_line');
auditH.addQuery('set',history.getValue('sys_id'));
auditH.addEncodedQuery("label=State^newISNOTEMPTY^oldISEMPTY"); // new is not epmty and old is empty
auditH.query();
if(auditH.next()){
incident.u_field = new GlideDateTime(auditH.sys_created_on).getDate();
incident.update();
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-30-2025 10:03 PM
If your table is audited then you can do.
if you have a custom field to store then below sample script you can enhance for your table and field (date/time type)
I am giving example for incident table
if table is audited then you can do this
You can do GlideRecord from following tables,
sys_history_set and sys_history_line
For e.g. I am fetching history for incident number 'INC0010016' and getting when State changed to some value from empty
var incident = new GlideRecord('incident');
incident.addQuery('number','INC0010016');
incident.query();
while(incident.next()){
var history = new GlideRecord('sys_history_set');
history.addQuery('id',incident.getValue('sys_id'));
history.query();
history.next();
var auditH = new GlideRecord('sys_history_line');
auditH.addQuery('set',history.getValue('sys_id'));
auditH.addEncodedQuery("label=State^newISNOTEMPTY^oldISEMPTY"); // new is not epmty and old is empty
auditH.query();
if(auditH.next()){
incident.u_field = new GlideDateTime(auditH.sys_created_on).getDate();
incident.update();
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
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-31-2025 01:36 AM
@Ankur Bawiskar : Thanks it worked👍