need a cleanup script to add a dictionary attribute exclude from rollback to tables in servicenow
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2025 12:03 AM
I need a cleanup script to add a dictionary attribute "exclude from rollback" to the tables after cloning.
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-08-2025 12:17 AM
something like this but please enhance
(function() {
// List the tables to exclude from rollback
var tablesToExclude = [
'incident', // Example: Incident table
'task', // Example: Task table
// Add your table names here
];
for (var i = 0; i < tablesToExclude.length; i++) {
var tableName = tablesToExclude[i];
var dictGR = new GlideRecord('sys_dictionary');
dictGR.addQuery('name', tableName);
dictGR.addQuery('element', ''); // Collection record for the table
dictGR.query();
if (dictGR.next()) {
var attributes = dictGR.getValue('attributes') || '';
if (!attributes.includes('excludeFromRollback=true')) {
if (attributes.trim() !== '') {
attributes += ',excludeFromRollback=true';
} else {
attributes = 'excludeFromRollback=true';
}
dictGR.setValue('attributes', attributes);
dictGR.update();
gs.info('Added excludeFromRollback=true to table: ' + tableName);
} else {
gs.info('excludeFromRollback=true already set for table: ' + tableName);
}
} else {
gs.info('Dictionary record not found for table: ' + tableName);
}
}
})();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Regards,
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader