GlideRecord • Business Rules • Client Scripts • GlideAjax
type your answer • check what you knowvar gr = new GlideRecord('incident'); // 1. Pick table
gr.addQuery('state', 1); // 2. Filter
gr.query(); // 3. Execute
while (gr.next()) { // 4. Loop
gs.info(gr.short_description); // 5. Do something
}addOrCondition() for OR logic, addEncodedQuery() to paste filter URLs, and get() to grab a single record by sys_id without needing query().
gr.addQuery('assigned_to', 'Fred Luddy'), it won't work because you're comparing a sys_id to a string.
// WRONG — comparing sys_id to a string
gr.addQuery('assigned_to', 'Fred Luddy');
// RIGHT — dot-walk to the name field
gr.addQuery('assigned_to.name', 'Fred Luddy');
// Chain them for deeper references
gr.addQuery('assignment_group.manager.email', '[email protected]');// CREATE
var gr = new GlideRecord('incident');
gr.initialize();
gr.short_description = 'New issue';
gr.insert();
// READ
gr.get(sys_id);
gs.info(gr.short_description);
// UPDATE
gr.get(sys_id);
gr.state = 2;
gr.update();
// DELETE
gr.get(sys_id);
gr.deleteRecord();get() doesn't need query() — it fetches a single record directly by sys_id.var gr = new GlideRecord('incident');
gr.addEncodedQuery('state=1^priority=1^assigned_toISNOTEMPTY');
gr.query();addQuery() calls, you get it all in one line. It's also easier to test — just paste the encoded query string back into a list filter to verify it.
update() because the system hasn't saved yet, so your changes get included in the same write.
current represents the record being acted on — it contains the new values about to be saved. previous holds the values from before the change. Together they let you detect what changed:
if (current.state != previous.state) {
gs.info('State changed from ' + previous.state + ' to ' + current.state);
}current.setAbortAction(true) in a Before business rule. Since it runs before the database write, you can cancel the operation entirely. Always pair it with an error message so the user knows what happened:
if (!current.short_description) {
current.setAbortAction(true);
gs.addErrorMessage('Short description is required');
}g_form it's client. If it uses GlideRecord or current, it's server.g_form methods that UI Policy doesn't cover (like showFieldMsg or addErrorMessage).
g_form.getValue('state'); // Get field value
g_form.setValue('priority', 1); // Set field value
g_form.setVisible('notes', true); // Show/hide field
g_form.setMandatory('notes', true); // Make required
g_form.setReadOnly('caller_id', true); // Make read-only
g_form.addErrorMessage('Fix errors'); // Error on form
g_form.showFieldMsg('state', 'Check', 'info'); // Msg on fieldvar MyAjax = Class.create();
MyAjax.prototype = Object.extendsObject(
AbstractAjaxProcessor, {
getIncidentCount: function() {
var gr = new GlideRecord('incident');
gr.addQuery('state', 1);
gr.query();
return gr.getRowCount();
},
type: 'MyAjax'
});var ga = new GlideAjax('MyAjax');
ga.addParam('sysparm_name', 'getIncidentCount');
ga.getXMLAnswer(function(answer) {
alert('Count: ' + answer);
});AbstractAjaxProcessor. This base class provides the framework for receiving AJAX requests from the client side and returning data. Without it, the GlideAjax call from the browser wouldn't know how to route to your function.
gs.info('message'); // Log to system log
gs.getUser().getFullName(); // Current user's name
gs.hasRole('admin'); // Check user role
gs.addInfoMessage('Saved!'); // Blue info banner
gs.addErrorMessage('Error!'); // Red error banner
current.setAbortAction(true); // Stop save (Before rules)