Database Views - multiple conditions on a where clause

Uncle Rob
Kilo Patron

So I built a database view with the following ...
TABLE: metric_definition ORDER: 100 WHERE CLAUSE: md_table = 'incident' && md_name = ' TCS...
TABLE: metric_instance ORDER: 200 WHERE CLAUSE: mi_definition = md_sys_id
TABLE: incident ORDER: 300 WHERE CLAUSE: mi_id = inc_sys_id

But I'd also like to put a condition where the incident's assignment group = a specific group (xyz)

I've tried using all kinds of syntax (AND, and, &&, &) to no effect. I'm thinking there's something fundamental I'm just not getting.

3 REPLIES 3

randrews
Tera Guru

I believe you have to put () around your && ||

http://wiki.servicenow.com/index.php?title=Talk:Database_Views


Hello,

 

Here is an updated wiki link in case someone needs it: https://docs.servicenow.com/bundle/madrid-platform-administration/page/use/reporting/concept/c_UseDi....

 

Regards

goscar79
Tera Contributor

Hi. 

I faced a similar challenge and my dev team told me that a Business Rule would make the trick. 

  1. Create a Business Rule, name it, and on the "Table" drop-down, select your view.
  2. Check "Advanced" checkbox, to enable the Advanced Tab
  3. On "Where to Run" make sure you have When='before' and check the 'Query' box
  4. On Advanced, create a text variable that will contain the query expression (In another tab I opened my database and "Try it", applied filters to the list, right click on the filter and "Copy query" to copy the expression) 
  5. use current.addquery(var name); to add it to the query
  6. Submit/Update
  7. Try your view again
  8. Magic!
(function executeRule(current, previous /*null when async*/) {

	// Add your code here
	var query = "in_sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()^ORin_sys_created_onISEMPTY^ah_model_category=b7d5bc14c3031000b959fd251eba8fd0^ORah_model_category=";
	current.addQuery(query);

})(current, previous);

 

Hope it helps!