Access all ServiceNow inbuilt methods defined in developer reference
Import
·
May 18, 2022
·
article
Dear all,
Thanks to a post from @Jeff Pierce that I was reading, I am sharing this small and useful piece of info which gets us an insight of how the methods which we often used are defined.
They are defined pretty much like how we define our methods in the Script includes.
To explore do this:
<INSTANCE_URL>/scripts/js_includes.js
AND
<INSTANCE_URL>scripts/js_includes_sp.js
A great reference for developers who want to make some of their Util functions.
Examples:
setReadOnly: function(disabled) {
if (disabled) {
var unlockElement = gel(this.name + "_unlock");
lock(unlockElement, this.name, this.name + '_edit', this.name + '_nonedit', 'ni.' + this.name + '.select_1', this.name + '_nonedit');
hideObject(unlockElement);
} else if (gel(this.name + '_edit').style.display == "none") {
var unlockElement = gel(this.name + "_unlock");
if (isDoctype())
showObjectInlineBlock(unlockElement);
else
showObjectInline(unlockElement);
}
gel(this.name).disabled = disabled;
return true;
},
getValue: function() {
return this.select.options[this.select.selectedIndex].value;
},
addOptions: function(glideRecord, nameField, valueField) {
if (!valueField)
valueField = 'sys_id';
if (!nameField)
nameField = 'name';
while (glideRecord.next())
addOption(this.select, glideRecord[valueField], glideRecord[nameField]);
},
getClassName: function() {
return this.getWindowDOM().className;
},
// THE FAMOUS GETTER AND SETTER
getValue: function(fieldName) {
return this[fieldName];
},
setValue: function(fieldName, value) {
this[fieldName] = value;
},
And every time we set a query condition, this is what gets executed:
addQuery: function() {
var fName;
var fOper;
var fValue;
if (arguments.length == 2) {
fName = arguments[0];
fOper = '=';
fValue = arguments[1];
} else if (arguments.length == 3) {
fName = arguments[0];
fOper = arguments[1];
fValue = arguments[2];
}
this.conditions.push({ 'name' : fName, 'oper' : fOper, 'value' : fValue});
},
So, lovely to see the logics behind what we are using.
ServiceNow, loving it ![]()
Cheers,
Anish
Labels:
View original source
https://www.servicenow.com/community/developer-articles/access-all-servicenow-inbuilt-methods-defined-in-developer/ta-p/2305377
