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
‎11-01-2013 03:33 AM
This is a very neat concept and code. Thank you.
And even if the sys_ids aren't same, You can still query to check the difference between two scripts by passing the respective code in
function I guess. I will be using the
doCompare
( didn't know about this earlier) in my Git implementation.
GlideBox
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-01-2013 06:01 AM
Yes, this is very cool. Thanks for sharing!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-13-2013 05:53 PM
Abhiram : Passing a different sys_id for the target instance does not work. Apparently this function
is matching the sys ids before rendering the comparison results.
diffHelper.getVersionTemplate
And
is the actual implementation class for
GlideBox
which is used by surveys as well as app creator popups.
GlideOverlay
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-14-2013 01:36 PM
That's a pretty neat script and it introduced me to a new type of GlideRecord I haven't become acquainted with. I did a Google as well as a Wiki search and didn't find much.
Anyone have a link to something that describes GlideRemoteGlideRecord?