Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Adding database view to report

cicgordy
Tera Guru

Hi all, 

I want to create a report in servicenow on the sc_req_item table and I want to show a list of hardware catalog item and group by department (cmn_department, only issue is that I cannot dot walk from a "department - reference field variable" to group by department and other fields on that table, how can I do that?

I thought of creating a database view, so far I created the view tables 

cicgordy_0-1699461180546.png

and added the following fields to each of them: cmn_department with following fields("u_catalog_variable" and "dept_head") and sc_req_item with following fields("requested_for", "due_date", "number", "request", "quantity", "cat_item" and "stage". (see images below)

cicgordy_1-1699461354670.png

cicgordy_2-1699461386344.png

 

 

How do I make the report work? I guess I need to add "where clause"? how can I do that? 

Thanks

3 REPLIES 3

Bert_c1
Kilo Patron

Review existing Database views to see examples of "Where" clauses.  Add a where clause on the sc_req_item table in the Database view that links a field on sc_req_item to 'cmn_department'.  Looking at the two tables, I see cmn_department has a reference field 'user' so your where clause "ritm_requested_for = dept_primary_contact" may work for you.

Hi @Bert_c1 , will you also be able to help me with writing the where clauses please? These are the three tables I created. Thanks

cicgordy_0-1699467557049.png

 

Please be clear on what fields in sc_req_item related to records in cmn_department. I posted a where clause in my previous response based on the DB view containing the two tables. You have added cmdb_ci since. There is a reference field named 'cmdb_ci' on 'sc_req_item' table to the 'cmdb_ci' table. to link those two tables, use: cmdb_sys_id=ritm_cmdb_ci for the where clause on that entry. but then linking cmn_department to cmdb_ci is not clear.