Database View Where Clause Confusion
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-03-2013 11:49 AM
Hello,
I'm trying to setup a very basic database view of the Service Catalog table (sc_cat_item). However, I'd like the view to contain only active items. When I try to setup the view, add the view table and setup a Where clause (cat_active = true), the resulting view returns all records in the table. Why is this? This seems like a simple enough "filter" clause....
Thanks,
Brandon

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-21-2014 04:42 PM
Hi, I am trying to setup a business rule that acts on a database view, just like you suggested, but it seems I cannot even filter it at all, for example I am looking for thos which STATE = 3 (which are Closed Complete).
Can you please explain further how you would apply the script conditions in the business rule? STATE = 3 and Active = true.
Thank you

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-16-2014 07:54 AM
Can you post the code you used in your Business Rule?
When you create a before query business rule, "current" represents the GlideRecord object referencing the target table (view) in this case.
You should be able to add as many query conditions to current as you need:
current.addQuery("fieldA", "valueA");
current.addActiveQuery();
etc.
I'm only guessing on your field names, but you probably need something like this:
current.addQuery("state", "3");
current.addActiveQuery();
See GlideRecord - ServiceNow Wiki (addActiveQuery())

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-15-2015 02:58 PM
A small correction :
I just wanna add this to your reply.
If someone is still not able to get the result. You might have missed the variable prefix.
This could be the answer:
current.addQuery("variable_prefix_state", "3");
current.addActiveQuery();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-14-2014 02:10 AM
the workaround is great, but have you tried to set the filter cat_active = 1 ?
It works for me
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-02-2017 05:32 AM
I tried this (because I don't want to make onquery business rules) but it doesn't work for me. Has anyone else successfully tried this?