- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 07:59 AM
Hi everyone,
I'm working within a scoped application and trying to programmatically generate a History Set record. I found the GlideHistorySet class in the documentation, but I'm not entirely sure about the correct usage or best practices for implementing it in a script.
Has anyone successfully done this before? I'd appreciate any guidance or examples.
Thanks in advance!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 08:09 AM
Hello @SoniShaily
You're on the right track using the GlideHistorySet API. There are a couple of points to keep in mind for clarity and reliability. Also, .refresh() is typically only needed for UI refreshes and may not be necessary in all cases.
Here’s a simplified and corrected script you can use:
// Load the record you want to generate history for
var record = new GlideRecord(tableName);
if (record.get(documentKey)) {
try {
// Create a history set object and generate the history
var historySet = new GlideHistorySet(tableName, documentKey);
historySet.generate();
// Optional: refresh the history set (useful for UI updates)
// historySet.refresh(); // Only if needed
} catch (e) {
gs.info("Error generating history set: " + e.message);
}
}
Let me know if you're working with a specific table or use case—happy to help further!
Thank You!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 08:01 AM
Use
GlideSysHistoryLine
(Manually log record access)
If you want to track record access or build an audit log:
var historyLine = new GlideRecord('sys_history_line');
historyLine.initialize();
historyLine.setValue('documentkey', 'incident:' + recordSysId);
historyLine.setValue('tablename', 'incident');
historyLine.setValue('user', gs.getUserID());
historyLine.setValue('viewed', new GlideDateTime());
historyLine.insert();
Safe, auditable, and scoped-compatible.
You can query these records to build a “recently accessed” view or custom history tracking.
✔️ If this solves your issue, please mark it as Correct.
✔️ If you found it helpful, please mark it as Helpful.
—
Shubham Jain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-07-2025 08:09 AM
Hello @SoniShaily
You're on the right track using the GlideHistorySet API. There are a couple of points to keep in mind for clarity and reliability. Also, .refresh() is typically only needed for UI refreshes and may not be necessary in all cases.
Here’s a simplified and corrected script you can use:
// Load the record you want to generate history for
var record = new GlideRecord(tableName);
if (record.get(documentKey)) {
try {
// Create a history set object and generate the history
var historySet = new GlideHistorySet(tableName, documentKey);
historySet.generate();
// Optional: refresh the history set (useful for UI updates)
// historySet.refresh(); // Only if needed
} catch (e) {
gs.info("Error generating history set: " + e.message);
}
}
Let me know if you're working with a specific table or use case—happy to help further!
Thank You!