Note: this is only applicable to Madrid or older ServiceNow versions. Since New York upgrade session debugging is done in a separate user friendly window.
NOW platform and Service Portal shares a lot of common utilities that are used in many places thorough the platform. For example, ACL’s, user criteria, text search are used in both parts of ServiceNow. We know we can use system diagnostics debugger tool on the platform, but what about the portal?
When we enable the debugger in the platform, at the bottom of our page,we can see what is happening under the hood of SNOW. For example, how are the database records we are trying to reach are processed, how ACL and user criteria rules were evaluated, what was the text search score for each returned item generated.
However, when we enable the debugger, this same information is not available at the bottom of our portal page.
So how do we debug platform-shared features in Service Portal?
You have to have 2 windows open. One must have Service portal opened and another one must have the platform.
On platform under ‘Session debug’ select ‘Enable all’.
Reload the current page you are on the portal or load any other portal page.
Go back to the platform and in the filter navigator type any non existing table/UI page name and add .do in the end, for example, isthisreal.do, or if you just want to get done with it faster something like ‘asdf.do’.
That’s it. Because this ‘ isthisreal’ page does not exist, it loads debugger information of the last page that was loaded successfully, which is in our case, the Service Portal.
Have you ever had a need to apply the effects of user criteria immediately, after the user performed certain actions, for example, changed his location or his language, therefore he must see different items in the catalog or the knowledge base immediately?
The out of the box way to apply User Criteria is tedious. First, the user needs to log out, which is something that everyone hates. The user has to go through multiple SSO white flashing screens or he has to re-enter his password. Overall, it might take up to 15 seconds untill user can use ServiceNow again.
Secondly, users want the effect to happen immediately. If you have changed your location from Norway to Sweden and you are still seeing only location specific requests for Norway employees, you might think it’s not working as expected. Everyone hates situations when they call Service Desk complaining something is not working and they are presented the same old question – ‘Have you tried logging out and in?’. There are no winners here.
Log out requirement is done for performance reasons: User Criteria
is cached and is only build once, when the user has logged in.
There are some drawbacks in OOTB UC set up:
1) User needs to log out and back in which can take some
2) Complete user cache has to be rebuilt from 0. I would
think this has quite some performance impact compared what I will suggest next.
Let’s say the criteria is based on user’s language and the user is using service portal. Let’s make sure he has no need to log out to see his language-based catalog items.
Now let’s create some Scripted user criteria records which would confirm the user criteria was applied immediately. Do this for Sweden and Norway. As in example:
Add the user criteria to some catalog items. Let’s say iPad’s can only be ordered if your language is Swedish, and iPhone’s if it’s Norwegian. Now let’s open the Service Portal:
You can see both criteria’s were evaluated and Sweden one was applied, however, when we change our language to Norway, this is not re-displayed and the criteria is not re-applied until we log out or clear server cache.
So how can we do it without logging out or clearing all server cache?
By clearing user’s private
user criteria cache object whenever he changes his language.
If we use cache inspector tool (more on my previous article), we can locate the UC cache object name: criteria_cache.
To add it to the portal let’s modify the ‘User Profile’
Service Portal widget by cloning it and adding the copy to our page. Modify the
server code whenever user language is changed to clear his UC cache with this
That’s it! No more need to log out and back in. Effects are immediate once you go back to the catalog.
Does this kind of scripted user criteria have performance implications?
No, because there is another user object cached which holds all user profile specific information, including his language setting. Therefore, user criteria scripts are only looking for the value in the cache and not performing any database queries.
Fix compatibility issues for SN unsupported unique corporate applications
First you will need to modify one ACL rule. Elevate your role
to security_admin, go to ACL’s menu, find the cache_inspect UI page read ACL rule
and select the “admin overrides” checkmark and save it.
Now go to the cache_inspect page by typing cache_inspect.do in
the filter navigator. You will be presented with the cache inspector (v2) tool.
Here you can browse through the Shared and Private cache. Shared cache is what is put to cache for use by all SN users. Private cache is something that is unique to the user’s cache. For example, his recently viewed UI pages, user criteria evaluations. If the user just logged in, his cache would not have as much information loaded as if he browsed through SN for an hour. This means that you will only see cached items here only If you visited it through the UI first.
Now select cache type: Private and locate “syscache_jelly_template”
property. This contains all cached jelly templates (UI Pages).
Jelly files have .xml extension, so you will see a list of xml files in your cache inspector and the name of the plugin it came with. Now, if you click on each of them you will find the source code for each of the page in the details tab.
Let’s take $sp page which is page for any service portal. It loads $sp.xml to figure out doctype compatibility, then loads the sp.xml to figure out which portal you want to go to and does the rest. Let’s do a short POC to show this actually works for this article’s sake.
In the filter navigator go to UI pages and create a new one.
Name it exactly as it is named in the cache without the .xml: $sp.
Paste the source code and modify it :
First remove the first line: java.lang.String (1112):
Next we can see that when opening any portal it first checks
your browsers doctype compatibility, if it is fine, then it starts loading
service portal, otherwise it redirects you to /ess page.
So, let’s just try the POC and do the opposite, if the
doctype is compatible, do not load the portal, but redirect to /ess page.
Now we save it and we go to /sp and there it is, you get
redirected to /ess. From the transaction log this is what we see (view_content.do
is the UI page for /ess):
So why does it work and what is actually happening?
Because every time you try to load any type of resource it
always first try to look in the database, if the database cannot be found for
the record then it looks into application node files, usually in the JAR files
or other non-compressed XML files.
All we need to do is put this in the database!
By creating a UI page, naming it $sp, the same name as it is
named in the JAR file – $sp.xml, it will always load the file from the database
first if it exists there.
But this is not supported by SN and is a customization?
Exactly, that is the reason why we would want to do it – to support
something we have to support in our unique corporate environment that
ServiceNow does not support officially. This can be labelled as a customization
as well and could become maintenance issue if not handled properly. But if you are
customizing in the right way then there is no problem modifying customer hidden