Created
November 13, 2017 11:37
-
-
Save d-oderbolz/21790c0fcac73c18643d37ec1e9b2040 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is a gist to show how to write a Service Now Script Include to return an array with | |
// the results of a query | |
// As an example, I use the sys_properties table, but of course, any table will do | |
var Toolbox_Functions = Class.create(); | |
Toolbox_Functions.prototype = Object.extendsObject(AbstractAjaxProcessor, { | |
getPropertyList: function (prefix) | |
{ | |
// 06.11.2017 - Return a list of System Properties whose name starts with prefix | |
try { | |
var arr = []; | |
var property_gr = new GlideRecord('sys_properties'); | |
property_gr.addQuery('name', 'STARTSWITH', prefix); | |
property_gr.query(); | |
while (property_gr.next()) | |
{ | |
// Push new value onto array. | |
// THIS IS THE CRITICAL LINE | |
arr.push(property_gr.getValue(name)); | |
} | |
return arr; | |
} | |
catch(err) | |
{ | |
gs.eventQueue("script.error", "", "ERROR: PSI_Toolbox_Functions.getPropertyList", err + " in line:" + err.lineNumber); | |
} | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
As an example, I created these 3 properties:
var Toolbox = new Toolbox_Functions()
var res= Toolbox.getPropertyList("sc.firewall.notify.")
gs.print(res);
[0:00:00.002] Script completed in scope global: script
*** Script: sc.firewall.notify.1,sc.firewall.notify.2,sc.firewall.notify.3
Now it works (compare to the bad code)