Export all Update sets to XML - UI Action
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2015 04:37 PM
This code is still in an early access state, unclean but still works. Go ahead and update/improve.
Mainly designed for dev instances, not recommended for prod instances unless you can justify its need.
It works by using out of the box functionality for exporting an update set, just multiplies it for each update set.
WHAT
This exports all update sets in one go with the use of a UI Action
Currently it is possible to export all update sets, including ones that aren't in the 'completed' state. This can be adjusted in the code.
HOW
Client UI Action calls an ajax Script Include that does all the processing and returns values to be redirected in a URL
XML update sets are downloaded by multiple redirections to a page with the export update set URL.
FUTURE
It would be nice to have the Update Set download and save as the name of the update set and not the default id it is given. Currently the name is stored in the file — Some code for this is commented out, but still needs work - this may not be possible.
Also to have it only export updates sets that are selected in the update set list — code for this exists is commented out below but still needs some work.
SET UP
Names are note compulsory- feel free to adjust as you like, changes will have to be made in the code.
Create a UI Action and Script Include with the following
UI ACTION
Name: Export All Update Sets to XML
Table: Update Set [sys_update_set]
Order: 200
Active: TRUE
Show update: TRUE
Client: TRUE
List link: True
Onclick: AJAXCallUpdateXMLs()
Script:
functionAJAXCallUpdateXMLs()
{
//maybe export selected list items in list view only
/* var entries = g_list.getChecked().split(",");
if (!entries || entries.length == 0)
return;
alert(entries);
*/
/* for (var i = 0 ; i < entries.length ; i++)
{
window.open("https://dev12053.service-now.com/export_update_set.do?sysparm_sys_id=" + entries[i] + "&sysparm_delete_when_done=false");
}*/
//ga.addParam('sysparm_entry_ids', entries.join(','));
// new GlideAjax object referencing name of AJAX script include
var ga = new GlideAjax("exportListUpdateSetXML");
// add name parameter to define which function we want to call
// method name in script include will be getFavorites
ga.addParam("sysparm_name", "getXMLs");
// submit request to server, call ajaxResponse function with server response
ga.getXML(ajaxResponse);
function ajaxResponse(serverResponse) {
// get result element and attributes
var result = serverResponse.responseXML.getElementsByTagName("result");
var message = result[0].getAttribute("message");
//check for message attribute and alert user
if(message)
alert(message);
//build output to display on client for testing
var output = "";
// get favorite elements
var favorites = serverResponse.responseXML.getElementsByTagName("sysID");
for(var i = 0; i < favorites.length; i++)
{
var name = favorites[i].getAttribute("name");
var value = favorites[i].getAttribute("value");
output += name + " = " + value + "\n";
window.open("https://dev12053.service-now.com/export_update_set.do?sysparm_sys_id=" + value + "&sysparam_name=" + name +"&sysparm_delete_when_done=true");
}
alert(output);
return true;
}
}
//downloadURI("https://dev12053.service-now.com/export_update_set.do?sysparm_sys_id=" + value + "&sysparam_name=" + name +"&sysparm_delete_when_done=true", name + ".xml");
//pausecomp(1000);
/*
function downloadURI(uri, name) {
var link = document.createElement("a");
link.download = name;
link.href = uri;
document.body.appendChild(link);
link.click();
// Cleanup the DOM
document.body.removeChild(link);
delete link;
}*/
function pausecomp(ms) {
ms += new Date().getTime();
while (new Date() < ms){}
}
SCRIPT INCLUDE:
Name: exportListUpdateSetXML
API Name: global.exportListUpdateSetXML
Client callable: TRUE
Accessible from: All application Scopes
Active: TRUE
Script:
varexportListUpdateSetXML = Class.create();
- exportListUpdateSetXML.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getXMLs : function() {
var result = this.newItem("result");
result.setAttribute("message", "returning");
//var index = 0;
var updateSet = new GlideRecord('sys_update_set');
//updateSet.addQuery('state','complete'); // adjust here to select completed updates only
updateSet.query();
//gs.log("count us = " + updateSet.getRowCount());
while(updateSet.next())
{
var retrievedUpdateSet = new GlideRecord('sys_remote_update_set');
retrievedUpdateSet.initialize();
retrievedUpdateSet.description = updateSet.description;
retrievedUpdateSet.name = updateSet.name;
retrievedUpdateSet.release_date = updateSet.release_date;
retrievedUpdateSet.remote_sys_id = updateSet.sys_id;
retrievedUpdateSet.application = updateSet.application;
var scopeGr = new GlideRecord('sys_scope');
scopeGr.get(updateSet.application);
if (scopeGr.isValid()) {
retrievedUpdateSet.application_name = scopeGr.name;
retrievedUpdateSet.application_scope = scopeGr.scope;
retrievedUpdateSet.application_version = scopeGr.version;
}
retrievedUpdateSet.state = "loaded";
var sysid = retrievedUpdateSet.insert();
var update = new GlideRecord('sys_update_xml');
update.addQuery('update_set', updateSet.sys_id);
update.query();
while(update.next()) {
update.remote_update_set = retrievedUpdateSet.sys_id;
update.update_set = '';
update.insert();
}
//gs.log("Export # = " + index++);
this._addValue(updateSet.name, sysid);
//gs.log("https://dev12053.service-now.com/export_update_set.do?sysparm_sys_id=" + sysid + "&sysparm_delete_when_done=true");
//action.setRedirectURL("export_update_set.do?sysparm_sys_id=" + sysid + "&sysparm_delete_when_done=true");
//redirect("export_update_set.do?sysparm_sys_id=" + sysid + "&sysparm_delete_when_done=true");
}
// all items are returned to the client through the inherited methods of AbstractAjaxProcessor
},
_addValue : function(name, value) {
var sysID = this.newItem("sysID");
sysID.setAttribute("name", name);
sysID.setAttribute("value", value);
},
type: 'exportListUpdateSetXML'
});
you should end up with a button like this
Please feel free to add any improvements and re-post
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-24-2018 08:48 AM
Servicenow has introduced a functionality to Export Updateset batch via UI actions Export Updateset batch and Visualize Updateset Batch.
I gave it a try and was able to export all the updatesets I needed into a single xml file. In order to do this I had create a dummy updateset and mark it as complete, then from list view I had to update the parent column of all the updatesets that I needed to export to this dummy updateset.
From the dummy updateset I can now click on UI action Export Updateset batch which generates an xml with all the updatesets..
in order to retrieve these updatesets, I can follow the regular process to retrieve updatesets and I see that servicenow has created the updateset records for all the updatesets I exported by following above process.
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-14-2018 01:55 AM
Yeah, Export Update sets is good. you can also send larger files straight to a MID server.
quick note: I have also noticed that ServiceNow runs better on Mozilla then Chrome these days
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-05-2018 02:19 PM
Minor Note:
If you are using chrome and only seeing 1 Update Set being exported check your pop-up blocker.
It was allowing 1 window.open() but blocking all the rest. Once I allowed all popups for my ServiceNow instance all came through.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2019 07:31 PM
Was a joke lol

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-25-2019 07:42 PM
You can now do this natively with Update Set batching.
How to Backup Your Update Sets in 4 Easy Steps
ServiceNow Nerd
ServiceNow Developer MVP 2020-2022
ServiceNow Community MVP 2019-2022