Adam Stout
ServiceNow Employee
ServiceNow Employee

In the Performance Analytics & Reporting Office Hours on July 23rd, we discussed different ways to query data from multiple tables, including Dot Walking, Related List Conditions, and Database Views. One of the use cases reviewed was pulling data from multiple m2m tables and joining data with non-reference joins using a Database View to report on what Reports are on what Dashboards.

In this post, we’ll review in more detail how to achieve this. I’ll assume you already know the basics of Database Views. If not, be sure to listen to the record from Office Hours before continuing.

Create a Database View

Navigate to Database Views and click “New”.

Note: Creating a database view requires admin access.

Once there, give the view a Name and fill out the Label, Plural (Label), and Description.

find_real_file.png

What these are isn’t necessary since they are just labels but remember what you used. Once this is complete, right-click on the header and click “Save”.

Add the Tables

Now that we have a view, we need to specify what tables to use. This view requires more tables than I usually use, given the complexity of the data. Here are the tables we need to add along with the variable prefix and where condition.

Table 

Order 

Prefix 

Where 

Left Join 

pa_m2m_dashboard_tabs 

 

100 

dt 

 

false 

pa_tabs 

200 

t 

dt.tab = t.sys_id 

false 

sys_portal 

300 

p 

t.page = p.page 

false 

sys_portal_preferences 

400 

prefrend 

p.sys_id = prefrend.portal_section && prefrend.name = 'renderer' && prefrend.value = 'com.glide.ui.portal.RenderReport' 

false 

sys_portal_preferences 

500 

prefrep 

p.sys_id = prefrep.portal_section && prefrep.name = 'sys_id' 

false 

sys_report 

600 

rep 

prefrep.value = rep.sys_id 

false 

report_stats 

700 

repstat 

rep.sys_id = repstat.report_sys_id 

true 

Tip: You’ll notice that pa_dashboards is NOT included in this view. This is not needed because pa_m2m_dashboard_tabs includes a reference to Dashboards so you can dot-walk to the Dashboard record if you want information from that record (like Owner or Group).

What my final view looks like:

find_real_file.png

Restrict the Fields

While not required, I recommend going back into each table record and set the “View Fields” to only the fields I need in the view. If you don’t, you have all the fields from all seven tables, making reporting a bit messy. The exceptions for this view are sys_report and report_stats, which I do not specify fields for, so all of the table fields will be included.

Here is an example of what the first table looks like:

find_real_file.png

Relabeling View Fields

For this view, the field labels still make sense even when combined, but if you needed to change the labels, check out this post on how to do that quickly and easily.

Verify the Results

We should be all set, so now click on the UI Action “Try It” to view the results.

find_real_file.png

Which gives us:

find_real_file.png

What’s Next

Now that we have this Database View, we use it where needed. Perhaps we add it as a related list on the Dashboard properties page or on the Report form (although this isn’t viewed very often). Maybe some reports and a dashboard based on this will help you as well.

Leave me a note in the comments about how you are using this.

23 Comments
Alon Grod
Tera Expert

@Adam Stout hi adam im getting this error

Screenshot 2024-11-01 at 0.21.40.png

dgarod
Kilo Guru

Alon, this article is a bit old. It is using old syntax similar to SQL where you would use Variable Prefix "." Field Name in the Where clause. Please use the new syntax Variable Prefix "_" Field name.

Example: dt_tab = t_sys_id and not dt.tab=t.sys_id

 

Hope this helps.

Alon Grod
Tera Expert

@dgarod I changed everything to be '_' instead of '.' and now im getting this:

Please help 

Screenshot 2024-11-01 at 7.06.36.png

Screenshot 2024-11-01 at 7.07.15.png

Alon Grod
Tera Expert

@dgarod 

Screenshot 2024-11-01 at 7.08.08.png

dgarod
Kilo Guru

Please note the "Order" column.  It is important too.

Hiranmayee Moha
Tera Expert

Hi @Adam Stout ,

 

Not able to fetch any records. pls provide any suggestion.

 

 

Thanks

 

HiranmayeeMoha_0-1739360943475.png

 

Hiranmayee Moha
Tera Expert

Hi @Alon Grod,

Would u pls tell me how did u resolve your issue?

 

Thanks

Hiranmayee

Dan_Kane
ServiceNow Employee
ServiceNow Employee

@Hiranmayee Moha this is most likely due to an issue in one of the Where clauses in the database view. Can you please post a screenshot of how you configured your database view? Make sure we get the entirety of the Where clauses. This is a complex database view, so it's pretty easy to miss one thing.

 

Also, do you use Legacy CoreUI dashboards (Responsive canvas) or do you use Platform Analytics expperience dashboards (Platform Analytics > Library > Dashboards)?

Hiranmayee Moha
Tera Expert

Hi @Dan_Kane !

"Thank you for your proactive approach in addressing this issue. Please find the requested screenshots below."

I use Legacy CoreUI dashboards.

 

HiranmayeeMoha_0-1739459713623.png

 

Duane van Gesse
Tera Contributor

This is a great article... thank you for providing the solution. This allows me to see what reports are related to dashboards. Also allows me to see "Last Used" information for each report. This will be a great help to cleanup CoreUI dashboards and reports.

I do have 2 quests/requests:

  • However, is it also possible to add "dashboard_stats" to this Database View and how?

  • Is there a Platform Analytics version of this Database View... an alternative of sometype seeing Platform Analytics doesn't support Database Views?