CapaJC
ServiceNow Employee
Options
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
12-20-2011
08:45 AM
There are some shortcuts in GlideRecord that aren't commonly used, but can save you a few keystrokes if you write a lot of scripts. Here's an example that uses four of them.
var gr = new GlideRecord("incident");
gr.addActiveQuery();
gr.addNullQuery("assigned_to");
gr.addNotNullQuery("assignment_group");
gr.addQuery("category", "hardware").addOrCondition("category", "software");
gr.query();
The first, gr.addActiveQuery(), is the same as doing gr.addQuery("active", true); There is also an addInactiveQuery() method.
The second, gr.addNullQuery("assigned_to"), is the same as doing gr.addQuery("assigned_to", "");
The third, gr.addNotNullQuery("assignment_group"), is the same as doing gr.addQuery("assigment_group", "!=", "");
The last one is a bit different. One way to include an "OR" condition that you might see in scripts is as follows:
var qc1 = gr.addQuery("category", "hardware");
qc1.addOrCondition("category", "software");
This will include records in either category. The qc1 variable ends up being a QueryCondition object, which is not important to know. QueryCondition has the useful method addOrCondition() that lets you do the OR query.
But there's no need for the two lines - you can combine them like in the example above, which actually is more readable (at least to me).
- 766 Views
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.