Database view with multiple tables

Allan Riisgaard
Tera Contributor

I'm not sure if this is the correct forum, but here we go:
I am trying to build a Database View that shows:
Servers Related to Application Services that again is related to Business Applications.
I am using the cmdb_rel_ci for relations:

srv_as_ba.png

It will not work.
I can make it show servers related to Application Services or Application services related to Business Applications, but combining the two is not possible.

I can make it work with the CMDB Query builder, but that solution is not suitable for my need.

I also tried with at Script Include solution, without luck.

 

Does anyone have a solution ?

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

If I'm following your example correctly in how I setup some sample CIs, you'll want your DB view to look like this - just no left join on 200 needed, from what you had:

BradBowman_0-1709131116732.png

This gives you too many records, which is a good start as you have all of the tables joined.  Now you just have to filter the list to only show the records that you want.  In my case I excluded Name (aps_name) != NULL, but you can add ba_name != NULL as well, or whatever.

 

Once you have the DB View manually filtered to only show the records you want, right click on the last filter breadcrumb and Copy Query.  Then create a before Query Business Rule using the view name as the table.  The script will use the query to always filter the results:

(function executeRule(current, previous /*null when async*/ ) {
	current.addEncodedQuery('aps_name!=NULL^ba_name!=NULL');
})(current, previous);

 

View solution in original post

4 REPLIES 4

Dr Atul G- LNG
Tera Patron
Tera Patron

Hi @Allan Riisgaard 

I am not sure, but try in report or in list view

1. Try to get cmdb_rel_ci

2. Then Servers Related to Application Services

3. Server related to Business Applications.

 

Try this way once, to check are we doing right or not.

*************************************************************************************************************
If my response proves useful, please indicate its helpfulness by selecting " Accept as Solution" and " Helpful." This action benefits both the community and me.

Regards
Dr. Atul G. - Learn N Grow Together
ServiceNow Techno - Functional Trainer
LinkedIn: https://www.linkedin.com/in/dratulgrover
YouTube: https://www.youtube.com/@LearnNGrowTogetherwithAtulG
Topmate: https://topmate.io/atul_grover_lng [ Connect for 1-1 Session]

****************************************************************************************************************

Brad Bowman
Kilo Patron
Kilo Patron

If I'm following your example correctly in how I setup some sample CIs, you'll want your DB view to look like this - just no left join on 200 needed, from what you had:

BradBowman_0-1709131116732.png

This gives you too many records, which is a good start as you have all of the tables joined.  Now you just have to filter the list to only show the records that you want.  In my case I excluded Name (aps_name) != NULL, but you can add ba_name != NULL as well, or whatever.

 

Once you have the DB View manually filtered to only show the records you want, right click on the last filter breadcrumb and Copy Query.  Then create a before Query Business Rule using the view name as the table.  The script will use the query to always filter the results:

(function executeRule(current, previous /*null when async*/ ) {
	current.addEncodedQuery('aps_name!=NULL^ba_name!=NULL');
})(current, previous);

 

Thank You very much - it worked 🙂

AndersBGS
Tera Patron
Tera Patron

Hi @Allan Riisgaard ,

 

A much better solution is to build it through the CMDB query builder, as this will give you the exact view that you're looking for.

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/