I recently had a project whose major requirement was the ability to unload data from an instance to a file that could be reloaded into another instance. Seemed simple enough at the time, there are built in script includes that allow this. The job is done. Well, not so fast. The specifics of the requirements made it such that the ExportWithRelatedLists script include didn’t quite work, and required some extension and hammering, which is what I did.
Not too long after that project closed, I was perusing the ServiceNow docs, searching for something completely different, and I ran across this quote in a discussion about available URL parameters:

“Specifies a file format, can be CSV, XML, PDF, or UNL (Unload).”

(emphasis added).

After doing some quick test runs on my developer instance, I discovered this would have made the requirement of the previous project trivial to implement and much easier to maintain. Here is a simple example of using the UNL parameter to unload data from a specified table:

gs.print(unloadTable(gs.getProperty('glide.servlet.uri'), 'incident', gs.getProperty('your.user.name'), gs.getProperty('your.password')));

function unloadTable(instance, table, username, password) {
var endpoint_path = table + ‘.do?UNL’;
var endpoint = instance + (instance.charAt(instance.length – 1) == “/” ? endpoint_path : (‘/’ + endpoint_path));
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod(‘get’);
request.setEndpoint(endpoint);
request.setBasicAuth(username, password);
request.setRequestHeader(“Accept”, “application/xml”);
var response = request.execute();
//Checking the response status omitted for brevity
return response.getBody();
}