GlideRecordSecure
- Class inherited from GlideRecord
- Performs the same functions as GlideRecord AND enforces ACLs
Non-writable Fields
- Are set to NULL when trying to write to the database
- canCreate() on the column is replaced with canWrite()
- if it returns false, the column value is set to NULL
Checking for NULL Values
- If an element can not be read because an ACL restricts access, a NULL value is created in memory for that record
- You do NOT have to check for read access
If(!grs.canRead()) continue; - the next () method simply moves to the next record in the GlideRecord object
GlideRecord can handle a variety of data manipulation tasks, but can it restrict data to certain users?
Yes, the GlideSystem methods discussed in module- 6, like hasRole(), canRead(), and canWrite()
Used in conjuction with GlideRecord will restrict data to users that have right roles.
However, you must include the appropriate conditional checks every time data is queried. This strategy is NOT considered best practice.
GlideRecord example
var count = 0;
var gr = new GlideRecord('mytable');
gr.query();
while(gr.next()) {
if (!gr.canRead()) continue;
if (!gr.canWrite()) continue;
if (!gr.val.canRead() || !gr.val.canWrite())
gr.val = null;
else
gr.val = "val-" + gr.id;
if(gr.update())
count++;
}
GlideRecordSecure example
var count = 0;
var grs = new GlideRecordSecure('mytable');
grs.query();
while(grs.next()) {
grs.val = "val-" + grs.id;
if(grs.update())
count++;
}