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

Making Better Catalog Macros Part 2

I posted very briefly about this around 2 years ago with the promise that I’d write a second more detailed post. This never happened, but its still one of the things I use all the time. And now Geneva has come along, there’s actually a slight ‘hack’ that’s needed to get it working really properly.

So just to recap, when creating a custom UI macro, to make it work a lot nicer, you should always add this input field to it:

<input id=”$[jvar_question_name]” style=”width:50%” name=”$[jvar_question_name]” value=”” class=”cat_item_option questionsettext”/>

What this would do is let g_form.setDisplay and g_form.setMandatory work with the UI macro. It would also save the value to the database as per any other variable.

Simple enough, but what does this actually do?

Continue reading

Case Insensitive Filter

Many of us use GlideFilter to compare condition fields to a particular record to see if the record matches the condition.

You’ll see an example of this in the Process SLAs business rule where the system runs through all the SLA definitions and checks if the current record matches the conditions on the SLA definition.

I have been using this recently on some custom code and configuration and noticed something that has never cropped up before, namely that the conditions are case sensitive. So what this means the conditions ‘name=ahmed’ is different to ‘name=Ahmed’.

Usually this doesn’t impact me because I don’t use free text fields on conditions, but in this scenario I needed to. What makes this more difficult is that GlideRecord is case insensitive. So if I did a gr.addQuery(‘name’,’ahmed’) it would bring back all records where name was ‘ahmed’ or ‘Ahmed’. Continue reading

Intercepting Record Access

For years I’ve been working with ServiceNow and every time, one thing that always got to me that I never understood how it was accomplished was when viewing a sc_request record in self service view, it always re-directed to the order summary UI page.

order_summary

I just couldn’t figure it out and just assumed it was some hard-coded logic hidden away from us… until now! (yes, I’m a little excited about this…)

Continue reading