Skip to content

Instantly share code, notes, and snippets.

@thisnameissoclever
Last active November 22, 2023 09:48
Show Gist options
  • Save thisnameissoclever/34332e65d40a01aae2b2799f3793b3ce to your computer and use it in GitHub Desktop.
Save thisnameissoclever/34332e65d40a01aae2b2799f3793b3ce to your computer and use it in GitHub Desktop.
ServiceNow: Get Methods and Properties of an object
var methodsAndProperties = [];
var testObj = new GlideFilter('a=b', 'rule'); //TODO: replace this with whatever object you want to test
getMethodsAndProperties(methodsAndProperties, testObj);
gs.print('\n' + methodsAndProperties.join('\n'));
/**
* Populates an extant array in-place, of methods and properties of a given object.
* @param methodsAndProperties {array} - the array to populate/modify in-place.
* @param testObj {object} - The object to get the list of properties for.
*/
function getMethodsAndProperties(methodsAndProperties, testObj) {
var prop;
for (prop in testObj) {
try {
if (typeof testObj[prop] === 'object') {
methodsAndProperties.push(prop + ' {}');
} else if (typeof testObj[prop] === 'function') {
methodsAndProperties.push(prop + '()');
} else {
methodsAndProperties.push(prop);
}
} catch(e) {}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment