- Use
getUniqueValueto get sys_id. - Use
newRecordinstead of instantiating to get a new record with default values. - Dot-walking on GlideRecord returns GlideElement, use
getRefRecordto get GlideRecord.
- Use
getBooleanValuefor boolean fields.
Console output too chatty?
Set com.glide.util.Log.developer_filter = true to cut down on non-interactive console log entries such as scheduled workers. (Don't forget to remove it when you're done!)
Note: Fast! These don't need a database.
| /* | |
| * JSUtil already has some utility functions, Some more utility functions. | |
| * Written by diddigiabhi@gmail.com | |
| * Re-written for Service Now from underscore.js: http://underscorejs.org/ | |
| * | |
| */ | |
| var JSUtil2 = Class.create(); |
| // This is just a handy snippet I use when troubleshooting glide records | |
| // in a background script to quickly see all the properties and values of a glide record | |
| // Just change the table name and query for the glide record to test | |
| var gr = new GlideRecord("<your_table_name>"); | |
| gr.addQuery("<field_name>", "<value>"); | |
| gr.query(); | |
| while (gr.next()) { | |
| for (var prop in gr ){ |
| The -- None -- option may not have a sys_choice record associated with it. | |
| A choice list field set to -- None -- evaluates to these values, depending on the script context as listed below. | |
| For client-side scripts,such as client scripts: "" (empty string) | |
| For server-side scripts, such as business rules: "0" (string of the number zero) |
| function (someString) { | |
| // test string is opened with curly brace or machine bracket | |
| if (someString.trim().search(/^(\[|\{){1}/) > -1) { | |
| try { // it is, so now let's see if its valid JSON | |
| var myJson = JSON.parse(someString); | |
| // yep, we're working with valid JSON | |
| } catch (e) { | |
| // nope, we got what we thought was JSON, it isn't; let's handle it. | |
| } | |
| } else { |
| var fieldTypes = new GlideRecord('sys_glide_object'); | |
| fieldTypes.addQuery('sys_id', 'IN', ['sys_id_1', 'sys_id_2']); | |
| fieldTypes.setValue('visible', true); | |
| fieldTypes.updateMultiple(); |
UI Page consists of jelly, client script and processing script. UI Macro has the jelly script only (but client script can be injected in jelly script) Usages:
https://<instance_name>.service-now/<ui_page_name>.do// Snippet 1
var gm = new GlideModal('UI_dialog_name');
gm.setTitle('Show title');