Finding Logged In Users

Whenever I bring up how to check whose logged into the system, the usual response is ‘just click the logged in users module!’. Well I’m here to tell you that it doesn’t work like that, and to explain why, and then give a way of actually finding out (best endeavour anyway, it’s not the most elegant of solutions I think!).

So first of all, examining the logged in user table within within ServiceNow you can see that it starts with a v_. Immediately this tells you it’s not a normal table (I think the v stands for virtual). If you were able to look at the actual database, you would see this table doesn’t exist. So what’s it displaying?
Continue reading

Generate Schema Definition

Updated the code because of a bug
At one of my clients, we were integrating with a number of systems. One in particular had asked for a schema definition of the tables they were reading from and writing to.

So I decided to write a script to provide a JSON output of the schema. As it’s going through the columns of the starting table, if it finds a reference field, it’ll do the columns of that table, and if it finds a reference field there it will do the same again.

It does this up to 5 levels deep. If it finds a self referencing reference field (such as manager on the sys_user table, it’ll just put in ‘Recursive Reference’).

ServiceNow will output it in one long string, but if you go to a site like Dirty Markup and paste the details, it’ll format it nicely for you.

Continue reading

Dynamically Add/Remove Roles

I was working on a requirement recently where the customer didn’t want any admin to have permanent admin rights to the system.

The administrators could fulfil most of their work using other lower roles (itil, user_admin, knowledge_admin etc.). A bad experience where an admin accidentally did something they shouldn’t have, meant they wanted more rigour around the admin role.

What they asked for was if it was possible that admins could request the admin role via a service request and so it could be audited and then automatically removed after a set time period.

I’m not going to talk about the whole solution that was implemented here (maybe another time), but what I do want to show is how I added and removed particular roles on login and as part of the workflow. The usual approach to giving someone a role is to add it to their user record and then ask the user to log off and on again.

When trying to dynamically change their roles on login, this wasn’t an option. Continue reading