how to update existing additional comments with new value in request table
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2022 03:29 AM
HI All,
I want to update my existing comments with new value in request table how it is possible through script for multiple records.
- Labels:
-
Request Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2022 04:01 AM
Can you explain a bit more on your business requirement?
Where exactly you want to write the script?
Thanks,
Murthy
Murthy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2022 04:06 AM
HI Murthy,
Like while raising request i have entered my comments as "ABC" but now i want to update existing abc with "XYZ" can it is possible.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-07-2022 05:54 AM
The journal entry for comments is stored in the sys_history_line table related to the sys_history_set table.
And you can see the record by right clicking on the form header of your record, History -> List.
var hiset = new GlideRecord('sys_history_set');
hiset.addQuery('id', record_id);
hiset.addQuery('table', record_table);
// Code to avoid duplicate logs
hiset.orderByDesc('sys_updated_on');
hiset.setLimit(1);
hiset.query();
while (hiset.next()) {
var liset = new GlideRecord('sys_history_line');
liset.addQuery('set', hiset.sys_id);
liset.addQuery('field', 'comments');
//liset.chooseWindow(windowStart, windowEnd);
// liset.setLimit(1);
liset.query();
var counter = 0;
while (liset.next()) {
if(liset.getValue('new') == "ABC"){
liset.setValue('new','XYZ');
liset.update();
}
}
Note this is a huge table and stores the audit history of all records.
Kindly mark helpful/correct if this resolved your query
Regards
Vinayak