Skip to content

Instantly share code, notes, and snippets.

@cmcdevitt
Created May 5, 2023 13:19
Show Gist options
  • Save cmcdevitt/102b9c2baae04c9f8a01ccbde740eee7 to your computer and use it in GitHub Desktop.
Save cmcdevitt/102b9c2baae04c9f8a01ccbde740eee7 to your computer and use it in GitHub Desktop.
Test if a table is derived (i.e. extended) for another table. For CMDB test if a class is part of a parent's class.
//Testing the CMDB Class of some made up hosts on my instance
//Positive Test
var NotThere = 'b69715668326e110b356df647daad3f8';//cmdb_ci_vm_object
var chrisOne = '5f7dfd9cc0a8010e00ab58006f14bdc5';//cmdb_ci_unix_server
var answer = false;
var rec = new GlideRecord('cmdb_ci');
rec.get(chrisOne);
//test = 'manufacturer=b7e7c073c0a801690143e7b7d29eb408'; //Works
//test = 'sys_class_name=cmdb_ci_unix_server'; //Works
//test = 'sys_class_nameINSTANCEOFcmdb_ci_unix_server'; //Works
test = 'sys_class_nameINSTANCEOFcmdb_ci_server'; //Works
answer = GlideFilter.checkRecord(rec, test);
gs.info("Answer Expect True: " + answer);
//Negitive Test
var NotThere = 'b69715668326e110b356df647daad3f8';//cmdb_ci_vm_object
var chrisOne = '5f7dfd9cc0a8010e00ab58006f14bdc5';//cmdb_ci_unix_server
var answer = false;
var rec = new GlideRecord('cmdb_ci');
rec.get(NotThere);
//test = 'manufacturer=b7e7c073c0a801690143e7b7d29eb408'; //Works
//test = 'sys_class_name=cmdb_ci_unix_server'; //Works
//test = 'sys_class_nameINSTANCEOFcmdb_ci_unix_server'; //Works
test = 'sys_class_nameINSTANCEOFcmdb_ci_server'; //Works
answer = GlideFilter.checkRecord(rec, test);
gs.info("Answer Expect False: " + answer);
//Global Scope Only :(
//Positive test
var NotThere = 'b69715668326e110b356df647daad3f8';//cmdb_ci_vm_object
var chrisOne = '5f7dfd9cc0a8010e00ab58006f14bdc5';//cmdb_ci_unix_server
var answer = false;
var rec = new GlideRecord('cmdb_ci');
rec.get(chrisOne);
answer = rec.instanceOf('cmdb_ci_server');
gs.info("Answer Expect True: " + answer);
//Negative test
var NotThere = 'b69715668326e110b356df647daad3f8';//cmdb_ci_vm_object
var chrisOne = '5f7dfd9cc0a8010e00ab58006f14bdc5';//cmdb_ci_unix_server
var answer = false;
var rec = new GlideRecord('cmdb_ci');
rec.get(NotThere);
answer = rec.instanceOf('cmdb_ci_server');
gs.info("Answer Expect False: " + answer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment