Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save pchaozhong/fe657b8dc68e7d8e27ce23696607a118 to your computer and use it in GitHub Desktop.

Select an option

Save pchaozhong/fe657b8dc68e7d8e27ce23696607a118 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