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-17-2025 12:20 AM
Yes that approach would be good changing the state value.
I guess there will be no consequences doing soo as we just changing the state.
Shashank Jain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2025 10:36 AM
Hi @Shashank_Jain ,
Yes, I'm just changing State value, not touching other area .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2025 10:38 AM
@chanikya , That's sounds good.
If you find the solution helpful , please mark it as accepted and close the thread.
Shashank Jain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-20-2025 11:10 AM - edited 08-20-2025 11:10 AM
If the solution was helpful, could you please mark it as accepted and close the thread. That will be much appreciated.
Shashank Jain
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-17-2025 10:48 AM
Hi @chanikya ,
simply run this is in the background script
take the sysid of the sys update version record which you want to set to previous to run the script
Please mark my answer as helpful/correct if it resolves your query.
Regards,
Chaitanya