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

Cancelling Your Transactions

Sometimes you can run a piece of code, click an action, just generally do something a bit heavier than you expected and the transaction hangs and takes a long time to complete.

If you are in a window with the top navbar visible (the part with your name and setting etc.), then you will see a red cross appear with the time running. Clicking the cross will cancel your transaction. But what if you’ve opened up the main window in a new tab without the navbar?

Continue reading

ServiceNow Performance Metrics

If you’ve ever had performance issues within ServiceNow, chances are you’ve gone to look at the performance dashboards to see if anything looks “funny” there. If not, you then check the stats.do page.

Recently I’ve been working on automated monitoring, spotting a situation arising before the customer notices the system is going into slowdown.

While doing this I’ve discovered a new table with a whole load of metrics to read from. Continue reading

Securing .list And .do Pages Via ACLs

Within ServiceNow, anyone can go to any table by manipulating the URL or via the navigation menu.

I.E, if you want to go to the incident table, even if you haven’t access to the incident module, you can just:

  1. go directly via the url: https://sn-instance.com/incident_list.do or https://sn-instance.com/incident.do
  2. in the navigation menu search bar, type incident.list or incident.do

Having ACLs in place makes sure that the actions that you don’t want to happen don’t happen (create, write, read, delete). However, what if you just want to stop navigating to that URL in the first place?

You can stop users getting to the page via the navigation menu by editing the ‘NavFilterExtension’ UI Script (it has very good comments in there and easy to edit to do what you want).

I accidentally stumbled across a neater solution, again using ACLs.
Continue reading

Accessing Tomcat Logs In Real Time

Update: Just to add that these Tomcat logs are node specific. So if you want to watch another user’s transactions, you need to  be on the same node as that user. To switch nodes, you can use my Chrome Extension that’s on the store. More info is here

When trying to debug an issue, you add alert statements, log statements and info messages to a script attempting to understand what’s going wrong.

Often you can find the root cause relatively quickly. But other times, no matter how hard you look, something seems to be failing at a lower level. This is where the Tomcat server logs come in handy.

Accessing these usually requires downloading the log file and tracking down the exact time to find the issue.

The easier option is to watch the logs being written in real time with this simple Out of the Box UI Page and loading up whichever action your performing in one window, and watching the logs on the other window side by side: Continue reading

Clearing Values On Catalog GlideList

A few days ago I posted custom functionality on how to set the value of GlideList variables. Today I had a request from a colleague to find out how to create an equivalent function to g_form.clearValue(variableName) on a GlideList. Again, it turns out this hasn’t been implemented for the new variable GlideList (amongst other functionality). I assume these will all be added over time in the future release, but for now, I wrote a quick function that can be used to replicate the functionality:

Continue reading