One common request I’ve heard a lot from customers and on the Service-now forums is to add the ability to present list modules in the left navigation pane along with a count of records from the corresponding list query. This functionality is something that we’re all pretty familiar with since it’s a standard part of most email clients (including Microsoft Outlook and Entourage).
A few months ago I (along with a few other people) worked on a bit of code that brought this functionality to Service-now. While it was a cool idea and it seemed to work okay at first glance, the solution was very performance-intensive and pretty buggy. Slow page load times, left navigation hanging, and other issues were a frequent occurrence. As a result, if anybody asked me about the solution I told them not to use it. I just had another request for this the other day and thought I’d take another crack at a solution. After several hours of work and a fair amount of testing I’ve come up with the Outlook-style Module Counts update set.
This customization includes the following features:
- Display the record count for any list module
- Completely code-free configuration
- Asynchronous AJAX means that you won’t have your left nav hang while your module waits for the query to return
- Per-module count coloring
- Per-module refresh interval. Refresh counts as often as needed for each module.
- Optional sort order field to sort results
- Optional ‘Count filter’ for counts independent of the module definition filter
Core components:
This solution really just requires a few key components. The bulk of the heavy lifting is done by a business rule on the ‘sys_app_module’ table called ‘Populate Counts Arguments’. The whole purpose of this business rule is to keep you from having to modify code. It runs before an insert or update of a Module record and populates the necessary HTML arguments to generate the module. The arguments contain all of the information about the table, filter, image, etc.
The second core piece is the ‘ModuleCount’ Script Include. The script include is called from the module arguments to execute a given query and return the result (number of records) back to the module for display.
Finally, there are a few new fields and a couple of UI policies to keep the UI from getting too messy
.
Usage:
So easy, a caveman can do it! I’ve designed this solution to be a completely code-free experience for anyone who uses it. The first step is to select ‘HTML (from arguments)’ as the module link type and check the ‘Show count’ checkbox. Once you’ve done that a UI Policy takes over and shows you all of the fields necessary to create your counts module. Simply create or modify your module just like you would with any regular list module and add the optional parameters as shown in the diagram below.
Related Links:
- Download: Outlook-style Module Counts
- Supporting Documentation: Installing an update set on your instance


Comments
Posted On
Nov 22, 2010Posted By
Brad TiltonWow. We’ve been using the outlook style functionality for a while, but it was a pain to update and was causing some performance issues and was buggy. After installing this update set I was able to recreate all ten of the modules I had in about 5 minutes. Huge time saver and it fixed our performance issues, thanks!
Posted On
Nov 22, 2010Posted By
Mark StangerAwesome! That’s great to hear. Please keep me posted on how it’s working for you. I did make a small update over the weekend to handle a situation where you might not specify an image in the module definition. I’ve fixed the code so that it adds the default module image for you if you don’t specify one. I also noticed in your instance that the ‘Refresh interval’ field is a regular text field instead of a choice field. You may have done that on purpose (which is fine) but if not you can personalize the dictionary for that field and change it to a choice field to get the dropdown options as shown in the article.
Posted On
Nov 23, 2010Posted By
Richard HussThis is Great Stuff (TM) – thank you.
Discovered a minor bugette; the business rule insists on adding an ‘x’ to the image URL, which is correct in most cases but not if the image is under UPLOADS. In this case the module’s “image” field already ends with an x and an extra one is not needed.
Posted On
Nov 23, 2010Posted By
Mark StangerGood catch. You can fix that issue by changing the top part of the ‘Populate Counts Arguments’ business rule to look like this…
var modImg = current.image;
if(!modImg){
modImg = '/images/nav_bult.gifx';
}
if(!/x$/.test(modImg)){
modImg = modImg + 'x';
}
var s = '';
s += "<img src='" + modImg + "'/><span id='modCount" + current.sys_id + "'></span>
";
I’ve updated the update set to include this fix.
Posted On
Nov 23, 2010Posted By
Richard HussBingo, I have it sorted now.
Posted On
Dec 02, 2010Posted By
Bill CollinsWho new a post 2 years ago in the community would have 550 reads and garner so much interest. Thank you very much. I will load it shortly.
Posted On
Dec 02, 2010Posted By
Bill CollinsIf I don’t want the count to match the filter can I change this line in the BR (actually, I would want to unlock the arguments and change in the module) as follows?:
count.addParam(‘sys_query’, ‘incident_state=1^EQ’)
This would count “New” status incidents among all open incidents.
Posted On
Dec 02, 2010Posted By
Mark StangerThe whole point of this customization is to keep you from having to modify the code. The best solution is simply to create a new module. The business rule is set up to always overwrite the contents of the ‘Arguments’ field based on the module settings so you’d have to break the entire setup to do what you suggest.
Posted On
Dec 03, 2010Posted By
Bill CollinsAgreed. Maybe a future enhancement would be for the count to have its own filter separate from the module. My original intent in the first post was to be able to show “New” incidents in the Open queue (module) such as Outlook can show a count of unread messages in the Inbox and not just the number of messages in the Inbox.
Posted On
Dec 03, 2010Posted By
Mark StangerI just added a new component to the update set to allow the specification of a separate ‘Counts filter’ for cases where users want to separate the count filter from the standard filter. Usage and download instructions have been updated in the article above.
Posted On
Dec 04, 2010Posted By
Bill CollinsI don’t know what to say. Thank you Mark!! You’re a gift. (I couldn’t think of a better way to put it w/o profanity)
I loaded it and couldn’t be easier to understand.
This should become a standard part of the tool.
Posted On
Jan 13, 2011Posted By
Bill CollinsMark, I am working with an instance which is company separated and also domain separated. It is very near one of SNC’s first production instances. Shortly after installing module counts I impersonated an ITIL user and the banner above the logo has the following characters ‘; }); Additionally, The left navigation frame and the list/form frame are empty.
This does not appear for an ESS user. One UI Policy and one Field Style was created after the install. I have deleted both. I also reverted the module to a “List of Records.” No change.
Is it possible this is from the update set? Thank you. Bill
Posted On
Jan 14, 2011Posted By
Mark StangerI guess it’s possible. The easiest way to check is just to delete the module that’s using the functionality and see if it reverts back to normal. The only pieces that do anything client-side are the module (with its arguments) and the ‘ModuleCount’ Script Include. The script include gets called from the module arguments so if you don’t have a module calling it then it wouldn’t be involved. If that does fix the problem then there’s probably an issue with the ‘ModuleCount’ script include being in the wrong domain or something.
Posted On
Feb 02, 2011Posted By
Brian BroadhurstI’ve been waiting for an opportunity to try this out – and that opportunity arrived today. It took me literally less than 5 minutes to download the update set, unzip it, upload it to an instance, preview and commit it, then apply it to a module – and this is going to be a huge benefit to my client. This is great stuff, Mark!
Posted On
Feb 08, 2011Posted By
ozThis is great thanks Mark
Posted On
Mar 24, 2011Posted By
RickMark
I’ve applied the update set to our dev instance and I’ve noticed a couple of items.
1 – The instance appears to constantly refresh (the spinning icon to the right of the global search box never goes away)
2 – The refresh interval field is not a choice list. I tried to change this in the dictionary, but it isn’t an option.
I’ve applied the latest module count update set from Servicenowguru.
Thanks for any help.
Posted On
Mar 26, 2011Posted By
Mark StangerI’m not sure what the issue might be. My only recommendation would be to try to reinstall the update set. As long as the ‘Refresh interval’ field is an integer you should be able to set the ‘Choice’ option. If that option isn’t available then you’ve probably got an issue with the field not being on the form or a UI policy hiding it when it shouldn’t be hidden.
Posted On
Apr 16, 2011Posted By
Jim CoyneThis is great, but I did find a small issue – the “Edit Module” menu item on the image disappears for Administrators.
Posted On
Apr 16, 2011Posted By
Mark StangerThis is what I get when Service-now adds new features
. You can fix this by changing the ‘Populate Counts Arguments’ business rule and then re-saving your module. You’ll need to change this line…
";
to this…
s += "<img src='" + modImg + "x' oncontextmenu='" + contextFunc + "'/><span id='modCount" + current.sys_id + "'></span>
";
I also noticed a couple of other issues that I’ve fixed in the update set. One was an issue where the module text may not display, and the other was a script error that looked ugly (though it didn’t affect the functionality). I’ve updated the update set so you may just want to download the latest version. All of the updates are for the single ‘Populate Counts Arguments’ business rule.
Posted On
Apr 17, 2011Posted By
Jim CoyneI downloaded the update set and loaded it into demo and it seems to still be to old code from January. It does not have the fix you mentioned above, it is adding an extra ‘x’ to the image name and the module name is not displayed. I added the fix above (removed the extra ‘x’ from the second line though) into Demo and the menu is there, but the module name is not displayed.
Posted On
Apr 18, 2011Posted By
Mark StangerNot sure how, but you got the old code somehow. I just loaded it into demo this morning and everything looks great.
Posted On
Apr 17, 2011Posted By
quikThanks for the update Mark,
Working Fine with my updated Instance
Cheers
Posted On
May 23, 2011Posted By
SandipThis is cool!
Thanks Mark
Posted On
Jul 06, 2011Posted By
AlexHas anyone noticed if this affects session timeout? We have been having issues with session timeout on our instance and in trying to debug the issue, I thought about this count. I was thinking that it might be this code because it makes an Ajax call. Any thoughts?
Posted On
Jul 06, 2011Posted By
Mark Stanger@Alex It might if you’re using a refresh interval. You could test this easily by changing your modules to not use a refresh interval or just turn off any modules using this functionality to see if the session timeout is affected.
Posted On
Jul 07, 2011Posted By
AlexI’ll try that Mark. Thanks for the input.
Posted On
Aug 11, 2011Posted By
AmrutaHi Mark,
I imported this update set in our instance and it was committed without any errors. When I personalize the Module form to and select the fields created with this update set, they do not appear on the Module form. I can see those fields selected in the personalize module form slushbucket.
The instance is upgraded with version 06-03-2011_1411.
Posted On
Aug 11, 2011Posted By
Mark StangerThe fields should be there, but you have to select ‘HTML (from arguments)’ as the module type for them to display.
Posted On
Dec 01, 2011Posted By
Jim CoyneIt’s possible that the form was personalized earlier so the changes may not come through in the Update Set. Just add the “Show count”, “Refresh interval”, “Count color” and “Sort order” fields to the form under the “Link type” field. I had that happen to me the other day.
Posted On
Sep 16, 2011Posted By
Jim CoyneI’ve got one small improvement for you – refreshing the module count when the user clicks on the link. If you modify the “Populate Counts Arguments” Business Rule and add the following line of code:
between these two lines:
s += " mod" + current.sys_id + ".appendChild(menu_link);\n";
so you end up with:
s += " menu_link.onclick = function() {refreshNumber" + current.sys_id + "()};\n";
s += " mod" + current.sys_id + ".appendChild(menu_link);\n";
…the module count will refresh for you when you click on the link.
It works just a little bit better because your module and list count are now in sync.
Posted On
Sep 17, 2011Posted By
Mark StangerGreat idea. I’ve made this modification in the update set.
Posted On
Feb 14, 2012Posted By
Angus MacQueenMark I have ‘upgraded’ to latest update set and I was hoping to see the module count change when I clicked on the link but it didn’t
I then took a look at the business rule and the amendment from Jim Coyne wasn’t there so I added it manually in our DEV instance but still no go.
Just so you know we already had a previous update set so I right clicked in the header and choose import XML – pointed to the XML and uploaded it, the looked in ‘Retrieve Update Sets’ and saw the previous update set with a status of Committed and the new one with a status of Loaded. I then commited the one that was set as loaded and deleted the previously commited one after backing out.
Any ideas please?
Posted On
Feb 14, 2012Posted By
Mark StangerLooks like it didn’t get added to my update set for some reason. I’ve uploaded a new version that contains that fix. As for why the module didn’t work even when you made the change manually, it is probably because you didn’t update the module record after making the change. You’ll need to change the module record and force a change in order for the business rule to populate the new parameters and force the left nav to refresh as well.
Posted On
Nov 30, 2011Posted By
Manuel PanmanHi there.
We make use of this great script in service-now.
We know wonder if it’s possible to use it in the new UI.
When we use the new UI and hide the menu, we have no indication or conuter visible.
It would be awesome to have it in the New UI as well. Is there any possibilty to use this functionality on the new menu bar?
Posted On
Nov 30, 2011Posted By
Mark StangerI think this is possible, but it is going to be tricky to make sure it looks decent when it’s done. The only reasonable solution I can think of would be to put the number directly below the corresponding icon but I’m not sure how good that will look.
Posted On
Dec 01, 2011Posted By
Jim CoyneI’m having a problem with Internet Explorer showing all those links in bold instead of normal text and with the underline when hovering over the link. I’ve tried adding
to the Business Rule, but that does not work. It will not even toggle the previously selected module from bold to normal like “regular” modules do.
It works fine in Chrome, Firefox, Safari and Opera, just that darn IE, and of course the client’s browser is IE
Posted On
Dec 01, 2011Posted By
Mark StangerWhat version of IE are they using? I just ran a quick test with IE8 and IE9 and I don’t see any issue (check out demo11 right now). If they’re still using IE6 then a bolded link in their browser should be the least of their concerns
.
Posted On
Dec 01, 2011Posted By
Jim CoyneI would agree with that
I just tried demo11 with both IE 7 and 9 with the same bolded text.
Posted On
Feb 17, 2012Posted By
Bill CollinsMark, I think Aspen introduced a bug for this. If the count is turned on, then when dragging to left shortcut bar with UI11 the icon and link path (description) does not come over. Bill
Posted On
Feb 17, 2012Posted By
Mark StangerAre you positive that this worked with UI11 before? I can get the module to add if I click the link and drag, but not if I click the icon and drag. Either way, the correct icon doesn’t get added. I think that’s a limitation of using a module of type ‘HTML (From arguments)’. I don’t have any fix built yet.
Posted On
Mar 14, 2012Posted By
Alex NorthFor instances which still encounter performance issues when implementing this customization, take a look at the tables and columns which each of the modules you apply it to is referring to. If the columns used to select or order the data are not indexed, this solution is still incredibly resource intensive on the database. This will lead to the navigation pane freezes described in earlier posts and also a performance degradation across your instance.
I would reiterate the warning at the top of the page:
“You should only use this for modules where you really need the functionality!”
Posted On
Mar 14, 2012Posted By
Mark StangerThis is a great point. This functionality uses the same queries that would be performed elsewhere in the system, just usually at a greater frequency. If you’ve got inefficient, large queries running against un-indexed fields, the problem will be magnified by using the module counts.
Posted On
May 09, 2012Posted By
Christian AnderssonHi Marc! This is really a great plugin and is widely used in our implementations. But right now we have problems when doing language translations on all modules with the Outlook style counter. Do you have a solution for this? The business rule that generates the HTML script does not care about the translations at all. Any idéas..
Posted On
May 09, 2012Posted By
Mark StangerThanks for the feedback. Unfortunately, I don’t have a solution for that at this time. Because the user language is session-related, dealing with the language needs to be done client-side, and that’s not a simple thing to do. I’ll post here if I get a chance to include this feature.