Blog

System Update Sets

Ever lose all your update sets on a clone over?

Your hours spent staring at code is valuable! Backup your stuff and rest easy.

ServiceNow Update Sets

Use System Update Sets to add your customizations to an Update Set

An update set is a group of configuration changes that can be moved from one instance to another. This feature allows administrators to group a series of changes into a named set and then move them as a unit to other systems for testing or deployment.

ServiceNow Code Backup (Single XML)

Backup your Update Set to XML

My biggest concern when dealing with multiple clients, is that one client will clone over development without telling me and my code would be lost.  Backup your update sets to XML if you have customizations that would be difficult to replace.  You can always delete the xml file after the code is promoted to production.

Another good tip is to remove the condition on the UI Action, "Export to XML" on the update set. You can export an update xml anytime then, the update set doesn't need to be Complete to export.

Tracked Customizations

Remember not all customizations are tracked in Update Sets. Below is list of tracked customizations:

Customizations Tracked by Update Sets

Use an implementation or release plan to keep track of your untracked customizations. You can also export single records to xml in certain cases.

Another good idea to add an "Add to Update Set" UI Action.  Then you can add any untracked code to an update set without messing around with xml files.

Add to Update Set UI Action

UI Action: Add to Update Set
Table: Global [global]
Form Link: true
List Choice: true
Show insert: true
Show Update: true
Condition: gs.hasRole('admin')
Script:addToUpdateSet();
function addToUpdateSet(){
    var url = GlideSession.get().getStack().bottom();
    current.setForceUpdate(true);
    current.update();
    var updateManager = new GlideUpdateManager2();
    var currTable = current.getTableName();
    if(currTable.startsWith('wf_') || currTable.startsWith('sys_ui_') || currTable == 'sys_choice' ||  current.getED().getAttribute('update_synch') == 'true' || current.getED().getAttribute('update_synch_custom') == 'true'){
        return;
    }
    else{
        updateManager.saveRecord(current);
    }
    if (current.hasAttachments()){
        addAttachments(current, currTable);
    }
    if (currTable == 'sys_attachment'){
        var attach_doc = new GlideRecord("sys_attachment_doc");
        attach_doc.addQuery("sys_attachment", current.sys_id.toString());
        attach_doc.orderBy("position");
        attach_doc.query();
        while (attach_doc.next()) {
            updateManager.saveRecord(attach_doc);
        }
    }
    var currentSet = new GlideRecord('sys_update_set');
    currentSet.get(gs.getPreference('sys_update_set'));
    gs.flushMessages(); 
    gs.addInfoMessage('Record(s) added to update set ' + currentSet.name + '.');
    action.setRedirectURL(url);
}
function addAttachments(record, table){
    var attach = new GlideRecord("sys_attachment");
    attach.addQuery("table_name", table);
    attach.addQuery("table_sys_id", record.sys_id.toString());
    attach.query();
    while (attach.next()) {
        var updateManager = new GlideUpdateManager2();
        updateManager.saveRecord(attach);
        var attach_doc = new GlideRecord("sys_attachment_doc");
        attach_doc.addQuery("sys_attachment", attach.sys_id.toString());
        attach_doc.orderBy("position");
        attach_doc.query();
        while (attach_doc.next()) {
            updateManager.saveRecord(attach_doc);
        }
    }
}