- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2017 08:09 AM
I'm very new to using GlideRecord. I'm writing an advanced condition to specify when to send an email notification. Right now my script is working for the "Field" notification(I'm not wanting to send the notification then). But now I need to add another statement to check if the sc_req_item is "IT"(and also not send the notification)... How would I add an OR statement to my script to include "IT". Thanks in advance
var gr= new GlideRecord("sc_req_item");
gr.addQuery("cat_item.name","Field");
gr.addQuery("request",current.getValue("sys_id"));
gr.query();
if(gr.next()){
answer=false;
}
else{
answer=true;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2017 08:13 AM
Hi akunk23,
See this link, this will provide you with what you're after:
http://wiki.servicenow.com/index.php?title=GlideRecord#addOrCondition
It should look something like below if 'IT' is the name of the item.
var gr= new GlideRecord("sc_req_item");
var qc = gr.addQuery("cat_item.name","Field");
qc.addOrCondition('cat_item.name', 'IT');
gr.addQuery("request",current.getValue("sys_id"));
gr.query();
if(gr.next()){
answer=false;
}
else{
answer=true;
}
For future GlideRecord querying, also see these links.
Also see 'Encoded Queries' and how to generate an encoded queries:
http://wiki.servicenow.com/index.php?title=GlideRecord#addEncodedQuery
Encoded Query Strings - ServiceNow Wiki
Thanks,
Robbie
Please mark correct and helpful by clicking on your post link (Glide Record Notification ) to help others with the same/similar question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2017 08:13 AM
Hi akunk23,
See this link, this will provide you with what you're after:
http://wiki.servicenow.com/index.php?title=GlideRecord#addOrCondition
It should look something like below if 'IT' is the name of the item.
var gr= new GlideRecord("sc_req_item");
var qc = gr.addQuery("cat_item.name","Field");
qc.addOrCondition('cat_item.name', 'IT');
gr.addQuery("request",current.getValue("sys_id"));
gr.query();
if(gr.next()){
answer=false;
}
else{
answer=true;
}
For future GlideRecord querying, also see these links.
Also see 'Encoded Queries' and how to generate an encoded queries:
http://wiki.servicenow.com/index.php?title=GlideRecord#addEncodedQuery
Encoded Query Strings - ServiceNow Wiki
Thanks,
Robbie
Please mark correct and helpful by clicking on your post link (Glide Record Notification ) to help others with the same/similar question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2017 08:14 AM
Hi,
You can try this code
var gr= new GlideRecord("sc_req_item");
gr.addQuery("cat_item.name","Field");
gr.addOrCondition("cat_item.name","IT");
gr.addQuery("request",current.getValue("sys_id"));
gr.query();
if(gr.next()){
answer=false;
}
else{
answer=true;
}
Thanks
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2017 08:19 AM
Another simplified way is to use an addEncodedQuery() instead of addQuery()
var gr= new GlideRecord("sc_req_item");
gr.addEncodedQuery("cat_item.name=Field^ORcat_item.name=IT^request="+current.getValue("sys_id"));
gr.query();
if(gr.next()){
answer=false;
}else{
answer=true;
}
Thanks
PS: Hit like, Helpful or Correct depending on the impact of the response
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-06-2017 08:15 AM
Hi akunk23,
You can add an or condition easily: http://wiki.servicenow.com/index.php?title=GlideRecord#gsc.tab=0
Thanks,
Laurie