Alternative to GlideRecord and GlidequeryDetailsWhat is It? GlideQuery is a modern, expressive, and safer interface to the Now platform. You use it where you might typically use server-side GlideRecord. As a wrapper over GlideRecord, it can catch mistakes earlier in the development process and simplify many queries. Server-side API for querying data Written in 100% JavaScript (global Script Include)Uses GlideRecordbehind the scenesAvailable starting with the Paris release Why? GlideQueryis guided by three principles. How to enable? GlideQueryrequires the GlideQuery(com.sn_glidequery) plugin be installed. Navigate to System Definitions -> Plugins.Search for GlideQuery.Select the InstallbuttonThe Activate Plugin window may show additional plugins that will be activated as well.Select the Activate button to install the plugin. Another way to install a plugin is through a script. To install the plugin for GlideQueryusing this method, follow these directions:Navigate to System Definitions -> Fix Scripts.Create the script below, save, run the script, and select proceed.A message with the time it took to run the script appears.Validate the script installed by using System Definitions -> Plugins. Advantages GlideQuery: Fail Fast -Improve the Feedback Loop GlideRecord has been used for many years. GlideQueryis new and this may be the first time you are seeing this type of code.One thing to note is the reduction of code. In these examples, 4 lines became 3, 6 became 4, and 7 became 5. Can you write code that is less formatted to make less lines? Sure, but less lines of nicely formatted code can save you time in development and be easier to maintain. Business Rule update / Insert Checks In this example, the GlideRecordtries to update a record on a table with a business rule that rejects start_datebeing after end_date.The code continues to execute, but the record has not been updated. GlideQuery: Be JavaScript -Isolated from Java Keeping it simple, stringly-typed (or stringly-types) usually occurs when a programmerdecides to use strings for every type of data type, despite there being better and more efficient data types available. This often happenswhen the developer doesn't know the correct programming practices necessary for what they are trying to accomplish and can lead to unpredictable results during program execution. Be JavaScript -Stack Traces One thing that has been a welcome change is the NiceError. Let’s take a lookat why this is a big change. A GlideRecord error provides a Java Stack Trace that can be confusing. GlideRecord Java Stack Trace QueryEventLogger: Invalid query detected, please check logs for details [Unknown field las_namein table sys_user]Invalid query detected, stack trace below [Unknown field las_namein table sys_user] com.glide.db.QueryEventLogger.logInvalidQuery(QueryEventLogger.java:56) com.glide.db.QueryEventLogger.logInvalidQuery(QueryEventLogger.java:47) com.glide.script.GlideRecord.isInvalidTableField(GlideRecord.java:2380) com.glide.script.GlideRecord.jsFunction_addQuery(GlideRecord.java:2031) sun.reflect.GeneratedMethodAccessor44.invoke(Unknown Source) sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) java.lang.reflect.Method.invoke(Method.java:498) org.mozilla.javascript.MemberBox.invoke(MemberBox.java:138) org.mozilla.javascript.FunctionObject.doInvoke(FunctionObject.java:670) org.mozilla.javascript.FunctionObject.call(FunctionObject.java:614) GlideQueryNiceErrorin comparison: NiceError: [2020-08-04T05:19:17.028Z]: Unknown field 'las_name' in table 'sys_user’. Known fields: [ "country", "calendar_integration", ... ] --------STACK TRACE ---------at [global] 'Schema' [sys_script_include:4e115aed73512300bb513198caf6a749]:358 (anonymous) at [global] 'GlideQueryActions' [sys_script_include:89cffabe29300010fa9b76addd33871b]:40... GlideQuery: Create, Retrieve, Update, and Delete (CRUD) glideQuery.insert(keyValues, [selectedFields]) ⇒Optional Inserts a single record, returning an Optional of the newly-created record. glideQuery.select(...fields) ⇒Stream Specifies which fields to return and returns a Stream containing the results of the query. glideQuery.selectOne(...fields) ⇒Optional Similar toselect(), however only returns an Optional which may contain a single record. This is more efficient than select() if you only need one record, orwant to test if a record exists. glideQuery.update(changes, [selectedFields]) ⇒Optional Updates an existing record. Requires a where call, specifying all existing primary keys (usually sys_id). Returns an Optional of the newly-updated record. Passes in a reason string (just like GlideRecord'supdate). glideQuery.deleteMultiple() ⇒nothing Deletes all records in the table specified by preceding whereclauses. GlideQuery: Optional Class Example GlideQuery: Performance Considerations Performance Considerations You may be asking yourself, if GlideQueryis the latest technique for working with data, then why does it take longer to query data? GlideQueryis an API for GlideRecord.GlideRecordrecord values need to be converted into JavaScript values. This can account for 4% to 6% overhead in a query. Also, Insert and Update will have some overhead due to the checking that occurs. Even with the drop in performance, GlideQuerycan avoids poorly written GlideRecord since its syntax is geared to use the most efficient code available. Future Work GlideQuerybrings many new features, but there is still work that needs to be done. Scoped table permission checking -If tables are locked down and GlideQuerydoes not have permission to write to scoped tables, then GlideQuerycan not access scoped data.Allow opting out of field/choice checking -In special cases, fields may not exist, and opting out would help.