How to fix update set
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2025 08:42 PM - edited 08-16-2025 08:46 PM
Hi All,
Request. : Please let me know, can we fix this by running script ? is there any consensus if we fix them by script in servicenow.
two update version records has current state, so to fix this I have used below script. it fixed successfully .
var ga = new GlideAggregate("sys_update_version");
ga.addEncodedQuery("sys_created_onONLast 7 days@javascript:gs.beginningOfLast7Days()@javascript:gs.endOfLast7Days()^state=current"); // Last 7 days and State = Current //
ga.groupBy('name');
ga.addAggregate('COUNT');
ga.query();
while (ga.next()) {
var count = parseInt(ga.getAggregate('COUNT'));
if (count > 1) {
var name = ga.getValue('name');
var gr = new GlideRecord("sys_update_version");
gr.addQuery('state', 'current');
gr.addQuery('name', name);
gr.orderBy('sys_created_on');
gr.setLimit(1);
gr.query();
if (gr.next()) {
var sys_id = gr.getValue('sys_id');
var recordname = gr.getValue('record_name');
var updateType = gr.getDisplayValue('type');
var currentState = gr.getDisplayValue('state');
// ✅ Confirm sys_id matches a real record before updating
var target = new GlideRecord("sys_update_version");
if (target.get(sys_id)) {
target.autoSysFields(false);
target.setValue('state', 'previous'); // or your desired state
target.update();
gs.info(target.getDisplayValue('sys_created_on'));
gs.info(
"✅ Updated Record — Sys ID: " + sys_id +
" | Name: " + name +
" | Record Name: " + recordname +
" | Type: " + updateType +
" | Created on : " + target.getDisplayValue('sys_created_on') +
" | Previous State: " + currentState +
" → New State: "+target.getValue('state')
);
} else {
gs.warn("⚠️ Could not find record with sys_id: " + sys_id);
}
}
}
}
Please let me know, can we fix this by running script ? is there any consensus if we fix them by script in servicenow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2025 09:23 PM - edited 08-16-2025 09:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2025 10:46 PM - edited 08-16-2025 10:51 PM
First person work on script on 1st-Aug
there were many versions on script , so First person deleted that some specific unnecessary versions ,there were ran on script for that . While deleting they picked wrong condition it deleted all version .
2nd Person worked on same script on 2nd-Aug.
So we rollbacked from delete recovery successfully on 2nd-Aug .
now all versions came back successfully with Zero Errors. but two versions showing current(First person, 2nd person currently working ) .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2025 11:21 PM
There is one more way, you can delete these both versions and then create one new update set and capture this script in that version only with updated script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-16-2025 11:47 PM
Hi @Shashank_Jain ,
even though to delete those two we need to design Back-groundscript code on table.
sys_update_version
How about rather than deleting two records, If we simply set that single old record state value to "previous" ?