Update Sets Archives - ServiceNow Guru https://servicenowguru.com/tag/update-sets/ ServiceNow Consulting Scripting Administration Development Fri, 26 Jul 2024 12:31:18 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.2 https://servicenowguru.com/wp-content/uploads/2024/05/cropped-SNGuru-Icon-32x32.png Update Sets Archives - ServiceNow Guru https://servicenowguru.com/tag/update-sets/ 32 32 Easily Move Customer Updates Between Update Sets https://servicenowguru.com/system-definition/easily-move-customer-updates-between-update-sets/ https://servicenowguru.com/system-definition/easily-move-customer-updates-between-update-sets/#comments Fri, 26 Jul 2024 12:31:03 +0000 https://servicenowguru.com/?p=15964 As ServiceNow developers, we often encounter scenarios where we need to migrate configurations from one update set to another. Traditionally, this involves manually editing each customer update record to change its update set, which can be tedious and time-consuming, especially when dealing with a large number of updates. This article demonstrates how to streamline this

The post Easily Move Customer Updates Between Update Sets appeared first on ServiceNow Guru.

]]>
As ServiceNow developers, we often encounter scenarios where we need to migrate configurations from one update set to another. Traditionally, this involves manually editing each customer update record to change its update set, which can be tedious and time-consuming, especially when dealing with a large number of updates.

This article demonstrates how to streamline this process by creating a UI Action that allows you to move multiple customer updates between update sets with a single click.

Problem Statement
When you make configurations in your instance, there are times when you need to move these updates to a different update set. The conventional method requires opening each customer update record individually and changing the update set field to the desired update set. This method becomes impractical when dealing with numerous updates.

Solution
To overcome this challenge, you can create a UI Action that facilitates the movement of multiple customer updates to another update set in one go. This approach not only saves time but also reduces the risk of manual errors.

To begin, navigate to System Definition > UI Actions and create a new UI Action:

UI Action
Name: Move Updates to Current US
Table: sys_update_xml
Action Name: move_updates_to_current_us
Show insert: true
Show update: true
Client: true
List v2 Compatible: true
List Choice: true
Onclick: showConfirmDialog()
Script:

function showConfirmDialog() {

	var entries = g_list.getChecked();
	if (!entries || entries.length == 0)
		return;

	// this function runs when the modal close
	var callback = function () {

		// To send parameters to the server script we should use GlideAjax
		var ga = new GlideAjax('MoveUpdatesToCurrentUS');
		ga.addParam('sysparm_name', 'moveEntries');
		ga.addParam('sysparm_entry_ids', entries);

		// GlideAjax callback to refresh the related list
		var afterMove = function () {
			GlideList2.get(g_form.getTableName() + '.sys_update_xml.update_set').setFilterAndRefresh('');
		};

		ga.getXMLAnswer(afterMove.bind(this));
		return true;
	};

	var dialogClass = window.GlideModal ? GlideModal : GlideDialogWindow;
	var dialog = new dialogClass('glide_confirm_standard');
	dialog.setTitle(new GwtMessage().getMessage('Confirmation'));
	dialog.setPreference('warning', true);
	dialog.setPreference('title', new GwtMessage().getMessage('move_update_set_entries'));
	dialog.setPreference('onPromptComplete', callback.bind(this));
	dialog.render();
	
}

Two points I would like to highlight in this script.
– As we need to pass the selected records as a parameter to the server script, we need to use GlideAjax.
– For the callback function I needed to update only the related list. Initially I could only update the entire record but a quick search here on the portal led me to an article explaining exactly what I needed.

For the modal message to be displayed correctly, we need to create a record in the sys_ui_message table with the text we want.  Navigate to System UI > Messages and create a new message:

Now we need to create the Script Include that will perform all the necessary validations and actions. Navigate to System Definition> Script Includes and create a new script:

Script Include
Name: MoveUpdatesToCurrentUS
Accessible from: All application scopes
Client callable: true
Active: true
Description: Ajax helper class for helping the [Move Updates to Current US] UI action
Script:

var MoveUpdatesToCurrentUS = Class.create();

MoveUpdatesToCurrentUS.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    moveEntries: function () {

        var arrMoved = [];
        var objMoved = {};
        var arrNotMoved = [];
        var objNotMoved = {};
        var currUS_ID = '';
        var customUpdateLink = '';
        var customUpdateType = '';
        var baseURL = gs.getProperty('glide.servlet.uri');

        //create a link to the syslog to return the logs created by this SI on last 15 minutes 
        var sysLogQuery = 'sys_created_onONLast 15 minutes@javascript:gs.beginningOfLast15Minutes()@javascript:gs.endOfLast15Minutes()^messageLIKEMoveUpdatesToCurrentUS';
        sysLogQuery = encodeURIComponent(sysLogQuery); //https://www.w3schools.com/jsref/jsref_encodeuricomponent.asp
        var sysLogURL = baseURL + 'syslog_list.do?sysparm_query=' + sysLogQuery;
        
        // get the user current US
        var currUS = gs.getPreference('sys_update_set');
        var grUS = new GlideRecord('sys_update_set');		

        if (grUS.get(currUS)) {
            currUS_ID = grUS.getUniqueValue();
        } else {
            gs.info('[MoveUpdatesToCurrentUS] Error: Unable to get Current US.');
            gs.addErrorMessage('There was an error. Please review the <a href="http://'%20+%20sysLogURL%20+%20'">system logs</a> for more details.');
            return false;
        }

        // get the variable sent by the UI Action
        var entries = this.getParameter('sysparm_entry_ids');

        //get all selected custom updates
        var customUpGr = new GlideRecord('sys_update_xml');
        customUpGr.addEncodedQuery('sys_idIN' + entries);
        customUpGr.query();

        while (customUpGr.next()) {
            
            //check if the user can write in the table
            if (customUpGr.canWrite()) {

                //create a link to the current update and get its type
                customUpdateLink = baseURL + 'sys_update_xml.do?sys_id=' + customUpGr.getValue('sys_id');
                customUpdateType = customUpGr.getValue('type');

                // check if it trying to move do a diferent US
                if (customUpGr.getValue('update_set') == currUS_ID) {

                    objNotMoved = {
                        sys_id: customUpGr.getUniqueValue(),
                        reasonHTML: 'Custom US <a href="http://'%20+%20customUpdateLink%20+%20'">' + customUpdateType + '</a> is already in your currently US.',
                        reasonText: 'Custom US ' + customUpdateType + ' - ' + customUpGr.getValue('sys_id') + ' - is already in your currently US.'
                    };

                    arrNotMoved.push(objNotMoved);

                } else {

                    // move the customer update to de current US
                    try {

                        customUpGr.setValue('update_set', currUS);
                        customUpGr.update();
                        
                        objMoved = {
                            sys_id: customUpGr.getUniqueValue(),
                            reasonHTML: 'Custom US <a href="http://'%20+%20customUpdateLink%20+%20'">' + customUpdateType + '</a> was moved to your currently US.',
                            reasonText: 'Custom US ' + customUpdateType + ' - ' + customUpGr.getValue('sys_id') + ' - was moved to your currently US.'
                        };

                        arrMoved.push(objMoved);

                    } catch (e) {

                        objNotMoved = {
                            sys_id: customUpGr.getUniqueValue(),
                            reasonHTML: 'Unable to move the Custom US <a href="http://'%20+%20customUpdateLink%20+%20'">' + customUpdateType + '</a> due: ' + e,
                            reasonText: 'Unable to move the Custom US ' + customUpdateType + ' - ' + customUpGr.getValue('sys_id') + ' - due: ' + e
                        };
    
                        arrNotMoved.push(objNotMoved);

                    }

                }				

            } else {

                objNotMoved = {
                    sys_id: customUpGr.getUniqueValue(),
                    reasonHTML: 'Unable to move the Custom US <a href="http://'%20+%20customUpdateLink%20+%20'">' + customUpdateType + '</a> due to ACL restrictions.',
                    reasonText: 'Unable to move the Custom US ' + customUpdateType + ' - ' + customUpGr.getValue('sys_id') + ' - due to ACL restrictions.'			
                };

                arrNotMoved.push(objNotMoved);

            }			

        }

        // create 2 messages: one to the syslog and one to show to user
        var sysLogMessage = '[MoveUpdatesToCurrentUS]' + '\r\r';

        if (arrMoved.length > 0) {
            
            var successScreenMessage = 'Move Updates to Current US Action' + '<br><br>';

            sysLogMessage += 'Custom Updates moved:\r';
            successScreenMessage += 'Custom Updates moved:<br>';

            for (var i = 0; i < arrMoved.length; i++) {
                sysLogMessage += arrMoved[i].reasonText + '\r';
                successScreenMessage += arrMoved[i].reasonHTML + '<br>';
            }

            gs.addInfoMessage(successScreenMessage);

        }

        if (arrNotMoved.length > 0) {

            var failureScreenMessage = 'Move Updates to Current US Action' + '<br><br>';

            sysLogMessage += '\r\rCustom Updates NOT moved:\r';
            failureScreenMessage += 'Custom Updates NOT moved:<br>';

            for (var x = 0; x < arrNotMoved.length; x++) {
                sysLogMessage += arrNotMoved[x].reasonText + '\r';
                failureScreenMessage += arrNotMoved[x].reasonHTML + '<br>';
            }

            gs.addErrorMessage(failureScreenMessage);

        }		

        gs.info(sysLogMessage);
        
        gs.addInfoMessage('Customer Update(s) transfer has been completed. Please review the <a href="http://'%20+%20sysLogURL%20+%20'">system logs</a> for more details.');

        return true;

    },

    type: 'MoveUpdatesToCurrentUS'
});

Using

  • Open the update set from which you want to move few customer updates
  • Go to the Customer Updates Related List
  • Select all the updates you want to move
  • Click on [Move Updates to Current US] in the actions dropdown menu

  • If everything works fine all selected customer updates have been moved to your Current US and you will see a message – simple as that.

  • If any problems occur during the transfer, you will be notified.

  • Everything will be recorded in syslog

Benefits

  • Efficiency: Moves multiple updates simultaneously, significantly reducing the time required.
  • Accuracy: Minimizes the risk of errors associated with manual updates.
  • Usability: Provides a straightforward and user-friendly method for managing update sets.

 

By implementing this UI Action, you can enhance your productivity and ensure a smoother workflow when managing update sets in ServiceNow. This method is particularly beneficial in complex development environments where rapid and accurate configuration management is essential.

The post Easily Move Customer Updates Between Update Sets appeared first on ServiceNow Guru.

]]>
https://servicenowguru.com/system-definition/easily-move-customer-updates-between-update-sets/feed/ 2
Bringing the Update Set Picker back from the UI14 Gear Menu https://servicenowguru.com/ui-scripts-system-ui/bringing-update-set-picker-ui14-gear-menu/ https://servicenowguru.com/ui-scripts-system-ui/bringing-update-set-picker-ui14-gear-menu/#comments Thu, 28 Aug 2014 15:20:32 +0000 https://servicenowguru.wpengine.com/?p=5410 The ServiceNow Eureka release contains many new features and changes. Among these are some significant changes to the look and feel that are generally a very nice (and needed) improvement over previous versions of ServiceNow. I have heard a few complaints about the way that the Banner Frame has been reorganized though. Instead of having

The post Bringing the Update Set Picker back from the UI14 Gear Menu appeared first on ServiceNow Guru.

]]>
The ServiceNow Eureka release contains many new features and changes. Among these are some significant changes to the look and feel that are generally a very nice (and needed) improvement over previous versions of ServiceNow. I have heard a few complaints about the way that the Banner Frame has been reorganized though. Instead of having the update set, language, and application pickers, etc. available directly, they’ve been moved into a separate menu which is now accessed by clicking a gear icon in the header. While I understand ServiceNow’s reasoning for this – the old header bar was starting to look very dated and cluttered – the update set picker in particular is something that I believe really needs to be visible to admins and developers at all times. In this post I’ll show you a quick workaround you can apply to your system to bring the update set picker back where it belongs!

MoveUpdateSetPicker

The Solution…

There’s no way to get at the back-end code that controls the gear menu popup so our only option is to manipulate the UI using client scripting. Since this is a global issue independent of any specific table or form, we can use a UI script to target the Update Set picker element and move it to a different location on the page. The following script does just that, just make sure to remember to check the ‘Global’ checkbox on the UI script record. Enjoy!

‘MoveUpdateSetPicker’ UI Script
Name: MoveUpdateSetPicker
Global: true
Script:

addLoadEvent(moveUpdateSetPicker);function moveUpdateSetPicker(){
try{
//Only run if UI14
if($('navpage_header_control_button')){
//Fix Fuji styling
$('update_set_picker_select').className = '';
if($('update_set_picker').select('li')[0]){
$('update_set_picker').select('ul')[0].style.marginBottom = "0px";
$('update_set_picker').select('li')[0].className = '';
$('update_set_picker').select('li')[0].style.paddingRight="5px";
$('update_set_picker').select('li')[0].style.listStyleType ="none";
$('update_set_picker').select('li')[0].select('a')[0].style.color ="#FFF";
$('update_set_picker').select('li')[0].select('a')[0].style.border ="none";
$('update_set_picker').select('li')[0].select('a')[1].style.color ="#FFF";
$('update_set_picker').select('li')[0].select('a')[1].style.border ="none";
$('update_set_picker').select('li')[0].select('a')[2].style.color ="#FFF";
$('update_set_picker').select('li')[0].select('a')[2].style.border ="none";
$('update_set_picker_select').style.color ="#000";$$('.btn-icon').each(function(d){
d.style.lineHeight = 'inherit';
});
}
if($('update_set_picker').select('legend')[0]){
$('update_set_picker').select('legend')[0].remove();
}
//Move the update set picker from under the gear icon to the header
$('nav_header_stripe_decorations').insert({
top: $('update_set_picker')
});
//Make sure that UI14 doesn't change styling
$('update_set_picker').id = 'update_set_picker_new';
}
}catch(e){}
}

UpdateSetPicker-Moved

Moving the Home icon…

I’ve had a few people ask about moving the home icon back as well. This one is a bit more difficult because of the lack of a decent ID to target, not to mention the old-style icon. In this case, I think it’s probably easier just to create a new icon in the header. The following code could be placed inside of the ‘if’ statement in the update set picker code above to also add a ‘home’ icon in the header.

//Create a home icon in the header
$('navpage_header_control_button').insert({
before: '<button id="navpage_header_home_button" class="nav_header_button icon-home" style="display: inline; visibility: visible;" title="Home" aria-label="Home"></button>'
});

The post Bringing the Update Set Picker back from the UI14 Gear Menu appeared first on ServiceNow Guru.

]]>
https://servicenowguru.com/ui-scripts-system-ui/bringing-update-set-picker-ui14-gear-menu/feed/ 74
Manually Add a Record to an Update Set https://servicenowguru.com/system-definition/manual-update-set-inclusion/ https://servicenowguru.com/system-definition/manual-update-set-inclusion/#comments Tue, 26 Apr 2011 13:14:28 +0000 https://servicenowguru.wpengine.com/?p=3588 The primary mechanism in Service-now for transporting configuration changes between instances is the System Update Sets functionality. If you’ve worked with Service-now much at all, you’re familiar with this functionality and know that it can be a huge time saver. You also probably know that there are a few gotchas to update sets that can

The post Manually Add a Record to an Update Set appeared first on ServiceNow Guru.

]]>
The primary mechanism in Service-now for transporting configuration changes between instances is the System Update Sets functionality. If you’ve worked with Service-now much at all, you’re familiar with this functionality and know that it can be a huge time saver. You also probably know that there are a few gotchas to update sets that can cause problems if you don’t pay attention to them. One of these gotchas is that not all changes you make in your instance get recorded in update sets. Of course, this is by design and it’s usually a good thing that saves you from problems. There are, however, some situations where you need to capture updates to a specific record in a table even though you don’t want all of the records in that table being captured. In this article I’ll show you a solution to this problem.

Manual Update Set Inclusion

First, let me give a couple of examples where this might come in handy…

Example 1

You need to modify the ‘Autoclose incidents’ Scheduled job to run once a day instead of once every hour. You can make this modification in your development instance, but it won’t be captured in an update set because the ‘sys_trigger’ table doesn’t have the ‘update_synch’ attribute set. There’s a great reason for this too. The last thing you want is for all of the records in the ‘sys_trigger’ table (SLA jobs, Inactivity monitors, Trend jobs, etc.) recording every update they ever make to an update set. You would end up with literally thousands of garbage updates in your update set in a matter of days just from normal system operations!

Until now, the solution to this problem was to export and import the file between instances as an added, manual step to your code migration process. It works (and in some cases may still be necessary), but it’s one more step that you would probably rather not have to think about.

Example 2

You’ve created a new table and application in your instance. The records in this table need to automatically receive a number when they are created so you create a new record in the ‘Number maintenance’ (‘sys_number’) table. There’s only one problem. Since the number maintenance table doesn’t include the ‘update_synch’ attribute those records won’t be included in your update set. Again, there’s a great reason for this. Number maintenance records get updated every single time you create a new task record, template, or software license. You don’t want all of that extra numbering garbage coming over to your production instance and messing things up there. All you want is to record the creation of a single Number maintenance record for your new table. Again, you’re forced to fall back on the manual export/import process to move that single record between instances.

The Solution:

PLEASE understand that this is in NO way a replacement for the out-of-box Update Sets functionality! The same guidelines recorded on the Service-now wiki for tracking customizations apply. This solution SHOULD NOT be used as a way to capture large amounts of data modifications that should be moved via import sets.

So here’s the way I came up with to fix this problem. Simply create a new UI action record as shown below on the table(s) that you need to record single-record updates on. Once you add the UI action, you can click the ‘Force to Update Set’ link on any record in that table to add it to your currently-selected update set. The UI action does three things…

  1. Check to make sure the current table isn’t already recording updates
  2. Push the current record into the currently-selected update set
  3. Reload the form and add an info. message indicating the addition
‘Force to Update Set’ UI Action
Name: Force to Update Set
Table: Wherever you need it!
Action name: force_update
Form link: True
Condition: gs.hasRole(‘admin’)
Script

//Commit any changes to the record
current.update();//Check to make sure the table isn't synchronized already
var tbl = current.getTableName();
if(tbl.startsWith('wf_') || tbl.startsWith('sys_ui_') || tbl == 'sys_choice' || current.getED().getBooleanAttribute('update_synch') || current.getED().getBooleanAttribute('update_synch_custom')){
gs.addErrorMessage('Updates are already being recorded for this table.');
action.setRedirectURL(current);
}
else{
//Push the update into the current update set
var um = new GlideUpdateManager2();
um.saveRecord(current);

//Query for the current update set to display info message
var setID = gs.getPreference('sys_update_set');
var us = new GlideRecord('sys_update_set');
us.get(setID);

//Display info message and reload the form
gs.addInfoMessage('Record included in <a href="sys_update_set.do?sys_id=' + setID + '">' + us.name + '</a> update set.');
action.setRedirectURL(current);
}

Forcing an update from a Background Script

In some cases, it might not be desirable to include a UI action to perform this function. In that case, you can run a script from the ‘Scripts – Background’ module to force the record into an update set. Just replace the table name and sys_id of the record in the script below.

//Query for the record
var rec = new GlideRecord('sys_number');
rec.get('973c8e8a9d022000da615b13b3a22f32');
//Push the record into the current update set
var um = new GlideUpdateManager2();
um.saveRecord(rec);

Attachments can also be forced into an update set by including the attachment and attachment doc records. Just pass in the sys_id the same way. Thanks to John Andersen for the idea here. He’s created a script to add a full record and associated attachments all at once that you can find on his blog.

//Query for the record
var rec = new GlideRecord('sys_attachment');
rec.get('973c8e8a9d022000da615b13b3a22f32');
addAttachmentToUpdateSet(rec);

function addAttachmentToUpdateSet(attachmentGR) {
var um = new GlideUpdateManager2();
um.saveRecord(attachmentGR);

var attdoc = new GlideRecord('sys_attachment_doc');
attdoc.addQuery('sys_attachment', attachmentGR.sys_id);
attdoc.orderBy('position');
attdoc.query();
while(attdoc.next()){
um.saveRecord(attdoc);
}
}

The post Manually Add a Record to an Update Set appeared first on ServiceNow Guru.

]]>
https://servicenowguru.com/system-definition/manual-update-set-inclusion/feed/ 26
Installing an SNGuru Update Set https://servicenowguru.com/service-now-general-knowledge/installing-sncguru-update-set/ Fri, 01 Jan 2010 14:12:56 +0000 https://servicenowguru.wpengine.com/?p=1199 ServiceNow Guru hosts a variety of useful customizations that you can download and install directly in your Service-now instance. Here’s how you can get them installed! As with any customization you install on your system, you’ll want to thoroughly test SNGuru update sets before committing them to your production environment. 1Download the update set from

The post Installing an SNGuru Update Set appeared first on ServiceNow Guru.

]]>
ServiceNow Guru hosts a variety of useful customizations that you can download and install directly in your Service-now instance. Here’s how you can get them installed!

As with any customization you install on your system, you’ll want to thoroughly test SNGuru update sets before committing them to your production environment.

1Download the update set from the downloads section and unzip the downloaded file

2Ensure that you have installed the ‘System Update Sets‘ plugin on your instance

3Navigate to ‘System Update Sets -> Retrieved Update Sets’ in your Service-now instance and click the ‘Import Update Set from XML’ link at the bottom of the list

4Browse to the update set XML file that you extracted in step 1 and click the ‘Upload’ button

5Once the update set has been uploaded, open the ‘Retrieved Update Set’ record and click the ‘Preview Update Set’ button. Let the preview finish and then review the information or return to the update set.

6Once the update set has been previewed, open it and click the ‘Commit Update Set’ button. This process may take a while depending on the size of the update set you are committing. Once the process is finished, you will see a confirmation message as shown below.


Your update set is ready to use! You may need to refresh your browser to see any new applications or modules.

The post Installing an SNGuru Update Set appeared first on ServiceNow Guru.

]]>