Compare your code across Instances/Environments !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-31-2013 08:19 PM
Pasted below is the code which can be used to compare your code across different environments. Of course, the assumption here is that the sys ids will remain same across the sub prod(s) and prod.
doCompare();
function getRemoteObject(){
// Look for only the last modified versions of the script
// This is a GlideRemote call and is just like GlideRecord except that it is Remote . Hence the name glideremote 😛
var gRemote = new GlideRemoteGlideRecord('https://myinstance.service-now.com','sys_update_version')
gRemote.setBasicAuth('enteryournamehere','enteryourpasswordhere');
gRemote.addQuery('name','sys_script_include_90c4220521b81500f3788a874b8c00b8');
gRemote.orderByDesc('sys_created_on');
gRemote.setLimit(1);
gRemote.query();
if(gRemote.next()){
//gs.print("remote");
return gRemote;
}
else{
return null;
}
}
function getLocalObject(){
// Look for only the last modified versions of the script
var gLocal = new GlideRecord('sys_update_version');
gLocal.addQuery('name','sys_script_include_90c4220521b81500f3788a874b8c00b8');
gLocal.orderByDesc('sys_created_on');
gLocal.setLimit(1);
gLocal.query();
if(gLocal.next()){
//gs.print("local");
return gLocal;
}
else{
return null;
}
}
function doCompare(){
// This is a SI Helper class that ServiceNow uses to compare the code from the Versions table.
var diffHelper = new DiffHelper();
/* Fetch the local and remote objects. These calls can be used to pass in the parameters to
replace the hardcoded values. The update version name is in this format - name of the table_sys id
*/
var gLocal = getLocalObject();
var gRemote = getRemoteObject();
if(gLocal!=null && gRemote!=null && gLocal.getValue('payload')!='' && gRemote.getValue('payload')!=''){
// This is the part which actually generates the side by side comparison
var diff = diffHelper.diffXMLString(gLocal.getValue('payload'), gRemote.getValue('payload'));
gs.print(diffHelper.getVersionTemplate(diff, gLocal, gRemote, true));
}
}
The code is simple enough and has comments where some explanation may be necessary.
The output from the above script can then be passed on to the Glidebox code below. This will generate the comparison results in an easy graphical format.
// abc is the output from the previous script block.
var dialog = new GlideBox({
body: abc,
title:"Code Comparison from Demo001 & Demo002",
height: "95%",
width: "95%",
autoDimensionOnLoad: 'false'
});
abc.evalScripts(true);
dialog.render();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-02-2018 01:01 PM
I'm in the same boat and couldn't find any documentation anywhere on this. In fact Google only had 4 search results for me.
As far as practical examples, I found 3 script includes where this API is used, UpdateSetAjax, UpgradeClient, EvtMgmtRemoteIncidentAdapter. If you go to System Definition > Script Includes > enter the name of one of the above, you can find them.
Here is an snippet from UpdateSetAjax:
var r = new GlideRemoteGlideRecord(url, 'sys_update_set');
r.setBasicAuth(user_id, password);
r.addQuery('sys_id', sys_id);
r.query();
From my own testing, there are several major distinctions and limitations of this class. The user has to have SOAP/REST roles. You can't access variables via the standard r.variableName, you have to use the getValue method for everything. There is that extra method setBasicAuth which takes a clear text username and password. The url (of the instance) & the table string, instead of just the table string in the constructor.
I ran a script to get all the methods of GlideRemoteGlideRecord, and below is the list. Just because the method is listed doesn't mean it's been implemented though.
getLastErrorMessage, isValidQuery, toXML, setupProxy, setHeader, setConnectTimeoutMillisecs, setACLGetter, getBooleanValue, canDelete, setRowNumber, getRowCount, getTableName, orderByDesc, hasNext, getError, setSuppressWarnings, operationByteCountinaccessible, addQuery, setLimit, setSocketTimeoutMillisecs, getTransactionTime, getRowNumber, wait, addQueryString, canRead, orderBy, notify, URLinaccessible, get, setSystem, setReturnDisplayValue, getLastErrorCode, setFactory, isValid, closeRecordStreamReader, canCreate, getSchema, setTimeout, getRecordsReader, getFloatValue, equals, setHttpState, toString, initialize, getClass, showQueries, transactionTimeinaccessible, setShowQueries, fromXMLDocument, setLogACLMisses, toDocument, fromXML, query, operationTimeinaccessible, getURL, setNewGuid, lastErrorCodeinaccessible, getKeysReader, next, setUseGZIPCompression, getOperationTime, setBasicAuth, getIntValue, notifyAll, insert, update, setDebug, delete, setAttribute, addEncodedQuery, setMaxRedirects, hashCode, classinaccessible, keysReaderinaccessible, isValidRecord, setRedirectSupported, getOperationByteCount, canWrite, setWorkflow, getValue, setValue, getDisplayValue, deleteRecord
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎12-12-2013 01:07 AM
Hi Anhuman,
Good Post and Interesting.
It seems the above code only works for script includes and we need to even hard code the script include sys_id value.Is there any way we can generalize this one to all the types of scripts eg:Business rules,UI Actions etc and with out hard coding.
Thanks,
Vamsi Kommireddi,
Certified System Administrator | ITIL V3 Certified