Calculating Field Usage

One of our customers is going through some rationalisation and simplification of their ServiceNow implementation. One of the many things we’re looking at, is reducing the number of fields available on CMDB and Task table. I couldn’t find any out of the box method to determine field usage, so I decided to attack this with a little background script.

The script goes through the base class that you pass in as an argument, and gathers all the fields available on that class. It then loops through these, discarding OOB fields by default.

It will then create a row for each extension class, the first column being the class name, followed by the total number of records directly on that class, followed by all the fields available on the table and their usage.

Once completed, it’ll create a CSV file and attach it to your user profile on the sys_user table.

A word of warning, it can take quite a while to run so either run it as a background script and get yourself a coffee, or run it as a fix script/scheduled job so you can continue working. Also consider running this outside of your core business hours.

I checked it on our customer’s CMDB table (1.5mil CIs) and it ran in 30 minutes and while the memory and CPU impact were minimal, running code during operational hours isn’t ever a good idea.

Continue reading

Using g_form On Fields Outside Of Your Scope

I am working on a new scoped app. One of the things it does is sets fields to mandatory.

My app is a generic app designed to work on all fields, whether in scope or not. But with the scoped apps this isn’t possible.

It turns out there’s a check that looks to see if the field you’re amending is part of the scope or not, and if not, will print an error in the console along the lines of:

Mandatory true not set on field impact: cross-scope access denied.

Continue reading