Amit Gujarathi
Giga Sage
Giga Sage
Hi Folks, This video will focus on the topic of Servicenow importance of the getValue and getDisplayValue method and try to understand the power of getters in snow. getvalue and GetDisplayValue have commonly used methods but we don't know the power of the same. Let's try to understand these methods in details I keep seeing a particular problem with people posting questions about data issues when using Arrays. And to be clear, it's not really an Array issue, but a problem with how data is retrieved from the GlideRecord object. Here's an example to illustrate the problem. The following 5 Incident records are in my personal development instance that has some OOB demo data: is putting the GlideElement object (in this case a GlideObjectNumeric because the field is an Integer) into the Array instead of the actual value of the field, so it changes as you loop through the records, becoming the value of the next record as you loop. To add the real "value" of the field to the Array, use this instead: log.push(gr.getValue("priority")); The "getValue()" method returns a string representation of the data in the field. This is the safest way to ensure you are putting the proper data into the Array, or any other variable. The issue is found more often in code when data is pushed into an Array because you are typically looping through multiple records, hence changing the "view" of the data, but it can happen anywhere. I hope I made it pretty clear why we should be using "getValue()" when getting data from a GlideRecord object. NOTE: "getValue()" does not work when dot-walking along with reference fields, so you will want to use "toString()" instead to force the value to a string (e.g. gr.caller_id.department.toString() to get the sys_id of the User's Department).