Skip to content

Instantly share code, notes, and snippets.

@cmcdevitt
Created September 7, 2018 14:37
Show Gist options
  • Select an option

  • Save cmcdevitt/7076eb412078ceb806b08f6635ce163e to your computer and use it in GitHub Desktop.

Select an option

Save cmcdevitt/7076eb412078ceb806b08f6635ce163e to your computer and use it in GitHub Desktop.
Add an "OR" Condition to a GlideRecord Query in ServiceNow
var myLog = "";
var gr = new GlideRecord("sys_user");
//New object to build OR query
var q1 = gr.addQuery("title", "CONTAINS", "VP");
q1.addOrCondition("title", "CONTAINS", "Vice");
q1.addOrCondition("title", "CONTAINS", "Chief");
//"switch back" to the GR object
gr.query();
while (gr.next()) {
myLog += gr.title + ", ";
}
gs.addInfoMessage("VPs : " + myLog);
gs.log("***CM: " + myLog, "CM");
@d-oderbolz

d-oderbolz commented Jul 23, 2024

Copy link
Copy Markdown

Note that there is also another way to add an OR query: you can use .addEcodedQuery() and then ^NQ to start a new query.
This is the same as writing (some query) OR (some other query).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment