Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

need a cleanup script to add a dictionary attribute exclude from rollback to tables in servicenow

Nafeesa bashir
Tera Contributor

I need a cleanup script to add a dictionary attribute "exclude from rollback" to the tables after cloning.

1 REPLY 1

Ankur Bawiskar
Tera Patron

@Nafeesa bashir 

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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader