logo

NJP

GlideRecord Pass By Reference Demo

wiz0floyd.do · Jan 10, 2023 · article

Have you ever needed help understanding why GlideRecord.field_name and GlideRecord.getValue('field_name') can behave differently? This is a simple script that demonstrates why it's important to use getters, especially when working with arrays. Simply run it in your browser console.

var obj = {

field: {

value: 0

},

next: function () {

if (obj.field.value < 10) {

obj.field.value++;

return true;

}

return false;

},

getValue: function (field_name) {

if (obj.hasOwnProperty(field_name) && obj[field_name].hasOwnProperty('value')) {

return obj[field_name].value.toString();

}

else {

return '';

}

}

};

var refarr = [];

var valarr = [];

while (obj.next()) {

refarr.push(obj.field);

valarr.push(obj.getValue('field'));

}

console.log(refarr);

console.log(valarr);

View original source

https://blog.wiz0floyd.do/2023/01/pass-by-reference.html