Join us Dec. 16 for The Community Hour, our first global virtual User Group event!
Yvonntje
ServiceNow Employee

Your company might have a need to report on Service Catalog Variables, one example for a use case might be to predict future requests to stock up on the right product.

Historically, it has been tricky to generate these kinds of reports in ServiceNow and we improved our variable reporting in newer releases. I will show you not only where the various variables are stored in relation to the Requested Item tables, but also how to build a database view that will link those tables and will work release independent.

A good way to report on Service Catalog Request Item Variables is using a Database View.   I will give you show you how to create a report on item variables using a database view.

In order to successfully create a database view to report on item variables in the service catalog, there are a few things you will need to know. First, the Requests are stored in the sc_request table. Second, the Catalog Items are stored in sc_req_item. Third, the variables you will find on the sc_item_option table. But, keep in mind that, the actual value for the variables in relation to the request is stored in sc_item_option_mtom.

Those of you familiar with Database views will know that sys_id is your best friend when linking tables, the same applies in this case.

sc_req_item links to sc_item_option_mtom by the sc_req_item sys_id

sc_item_option_mtom links to sc_item_option by the sc_item_option.sys_id

Confused? Let's see how to set this up, step-by-step:

Step 1: Create a Database View

To get started, you will need to create a database view. Start by navigating to System Definition > Database Views > New.

Give your Database View a meaningful name, in my example "screq_item_var_report." My label name is a bit long, "Request Item Variable Report," I thought for this example a descriptive name might be a good idea.

database view.jpg

Step 2: Create Tables for the database view

After submitting, a "View Tables" list will appear. Here, the tables you want to join will be added. Click "New" and enter the following:

  1. Table: Options (sc_item_option)
  2. Variable prefix: opts
  3. Order: 100
  4. Where clause: leave blank      
  5. Submit

add table.jpg

Add the second table, again Click "New"

  1. Table: Variable Ownership (sc_item_option_mtom)
  2. Variable prefix: varown
  3. Where clause: varown.sc_item_option = opts.sys_id
  4. Order: 200
  5. Submit

                                                                                                                                  add second table.jpg

You will notice that the View Tables List on the Database View is getting fuller, now the last one to be added.

  1. Click the new button.
  2. Table: Requested Item (sc_req_item)
  3. Variable prefix: reqitem
  4. Order: 300
  5. Where clause: varown.request_item=reqitem.sys_id
  6. Submit

view tables list db.jpg

Once the tables have been added to the Database view and all of the catalog request item options have been named, you will have completed your database view that allows you to report on Service Catalog items.

completed databse view report catalog.jpg

You can now create   a report based on "screq_item_var_report" and add fields like item, number, question, value etc. to will show the variables and their respective requested items.

27 Comments
hnie
Tera Contributor

We are having the exact same issue where the sys id is displayed because the variable is a reference. In our case, a reference to sys users, we would like to get the display value from sys users. Anyone know how to combine another table or to get the display value?


The Machine
Mega Sage

You would need to add sys user as a view table then in your where clause sys_id of answer equals the sys_id in the user table.



Then substitute the answer for the name in the sys user table in your view



Eric K3
Kilo Guru

Can you elaborate on your response?



What do you mean by 'answer?'


The Machine
Mega Sage

Sure!  So what I meant by answer is. The name of the field that is returning the sys_id of the user instead of the name. In your database view it's the prefix you defined for the many to many relationship of those variables and they're results.  




First add the user table to the views table and prefix it with something other than "user" I'll use "person" as an example.  




Then the where would be something like. Varown_<name of the field returning sys_id> = person_sys_id




Then in your database view you would use the "name" from the users table instead of the sys id in the m2m table.  




Hopefully that helps. I'm on a mobile device so I apologize if it's not clear.  




MB


The Machine
Mega Sage

I've done this for Record Producers and Surveys. The unfortunate part is that you need to have a view table for each question and that will put the entry all in one row. And it would be specific to that RP or Survey.  




It can be done but it's not scalable by any means.




So if my survey has 25 questions I had to call the survey response table 25 times. Not ideal but got the job done 🙂


Eric K3
Kilo Guru

OK. Thank you.



Now, what if we have dozens of variables that reference dozens of tables? I would have to include each of those tables in the database view in order to get the display values instead of the sys_id of all the reference variables?


Kalaiarasan Pus
Giga Sage

Am I missing something here? Isn't the recent way to dot the variables field directly on the reports instead of database view?


Uncle Rob
Kilo Patron

Yeah, except for some reason it's hella unreliable.


Kalaiarasan Pus
Giga Sage

Yeah but multiple rows for a single request isn't helpful either if you use database view


Kalaiarasan Pus
Giga Sage

Did any one find a way to view the display value of fields instead of sys Id? We have multiple variables on our form referring different tables. So adding a view table for every variable is not feasible.



PS: We are not using Explore analytics. So that is out of our equation.