GlideElement

The GlideElement class is not generally instantiated on its own, but it is used for elements in a GlideRecord object, and provides methods for interacting with them. An element generally refers to a data column in the record, such as the number field on a task record, or the sys_updated_on field of a record. You can access a GlideElement from a server-side GlideRecord object (for example, by using gr.number), or by using the getElement method of a GlideRecord object.

Best practice dictates that you always use the getter and setter functions: getValue(), and setValue() if you want to get the value of the field. Directly accessing the server-side GlideElement property however, will give you a reference to the GlideElement object.

Let's say for example, that we have a table with a column called short_description. When we query this table, we get a GlideRecord object populated with various properties. Each field in the table becomes a property in the GlideRecord object, but those properties are not just strings and numbers and other basic/primitive data types. Instead, each property corresponding to a field in the table/records is an object that is an instance of the GlideElement class.

That means that this field/property, gr.short_description, corresponds to a GlideElement object, with all of the methods you'll see next (and more; we're just going to cover the most useful ones here that developers are likely to use on a relatively frequent basis).

But this isn't without implications; perhaps you've heard JavaScript referred to as a loosely typed language. This isn't a colloquial term; it actually means that the data types in JavaScript are fluid. In many other languages, when you declare a variable and initialize it, you intrinsically link it to a given data type: string, integer, float, boolean, and so on. However, in JavaScript, you can declare a var, set it to a string value, and then later modify its value so it contains a number, and so on.

This is useful in some situations; for example, you set the value of the short_description field with a line of code such as gr.short_description = 'New short description.";. However, this can actually be a bad thing, since you're overwriting the GlideElement object that used to be in the parent GlideElement object's short_description property. Using the GlideRecord's setValue() method, however, correctly sets the value within the GlideElement object.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset