One common request I’ve heard a lot from customers and on the ServiceNow 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 ServiceNow. 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.
Wow. 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!
Awesome! 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.
This 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.
Good 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.
Bingo, I have it sorted now.
Who 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.
If 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.
The 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.
Agreed. 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.
I 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.
I 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.
Mark, 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
I 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.
I’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!
This is great thanks Mark
Mark
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.
I’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.
This is great, but I did find a small issue – the “Edit Module” menu item on the image disappears for Administrators. 🙁
This 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.
I 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.
Not sure how, but you got the old code somehow. I just loaded it into demo this morning and everything looks great.
Thanks for the update Mark,
Working Fine with my updated Instance
Cheers
This is cool!
Thanks Mark
Has 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?
@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.
I’ll try that Mark. Thanks for the input.
Hi 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.
The fields should be there, but you have to select ‘HTML (from arguments)’ as the module type for them to display.
It’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.
I’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.
Great idea. I’ve made this modification in the update set.
Mark 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?
Looks 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.
Hi 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?
I 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.
I’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 🙂
What 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 :).
I would agree with that 🙂
I just tried demo11 with both IE 7 and 9 with the same bolded text. 🙁
Hi Mark and Jim,
Thanks for sharing / enhancing this useful update set, very nice feature! We applied the “Valentines” edition and it worked well.
After a recent upgrade to Aspen_update2_hotfix5, we also encounter this minor issue with IE9, as described by Jim, normal style appear in bold.
Han Ying
Thanks for the feedback but I’m still not able to reproduce this issue. I’ve loaded the update set in demo05 and it appears to be working correctly there. Links are only bolded if they are clicked.
Mark, 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
Are 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.
For 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!”
This 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.
Hi 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..
Thanks 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.
This is awesome! One question (apologize if this already has been asked and answered).
Say I implement on Incident, for example. I have New (x), In Progress (x), Resolved (x), etc.
When I create a new Incident on the Incident form and hit Submit, I’d like to see the left navigation item updated – so New (x) should update to New (x+1) as soon as the new Incident record is created. The only way that updates now is if I click on New. I expect that I’d need to add either an entire left navigation refresh somewhere in your code – or perhaps can target the actual “New” module item and refresh that specifically.
Help or thoughts?
Thanks again!
Hey Joe,
I think the best you could do in that situation would be to set up a business rule on the table of your choice (incident, for example) to refresh the entire left Nav. I just wrote a post showing the scripts necessary to do this.
https://servicenowguru.wpengine.com/system-ui/refresh-left-navigation-pane-script/
Mark,
Once again, awesome! This perfectly aligns the creation of a new record with the counter update in the left navigation real time – and it’s very seamless from a UI perspective.
One final question on the topic and then I’ll leave you alone =)
I’ve been led to believe that it is not possible to persist a global group by in a native left navigation list (i.e. click Incident (All) and return a list with all incidents grouped by State). To account for that, I’ve created reports (where you CAN persist global group by) and then made the left navigation item “Run a report”. Your counter solution doesn’t allow for the use of reports as you must select “HTML from arguments”. Any thoughts on how I might use the counter functionality but also link to a report vs. the native list? Or if I’m mistaken on the lack of being able to persist global group by on a native list, I’d jump at that option as well.
Thanks again, you are a fantastic resource to the SN community.
Thanks Joe,
You should be able to sort or group records in a list by using the ‘Sort order’ field. You could group by state like this…
GROUPBYstate
Any idea with using this solution we can hide the breadcrumb? If we right click on the list and do a personalize and then omit filter, it does that for every list that is on that table. I just want to hide the breadcrumb on specific links that we build with this.
Unfortunately no, this doesn’t provide any additional capabilities around the display of a list filter.
Mark,
I am having a problem with this in IE 8. The count works well but each item shows as bold, so it starts to get a little ugly. Any thoughts?
This is a sweet tool and demonstrates a number of useful concepts. Thank you for this.
I modified the Business Rule ‘Populate Counts Arguments’ to only rewrite the link when Count>0.
It is small change but for those that do not do any coding, you can replace the function defined at the bottom of the rule to this…
s += " var answer = response.responseXML.documentElement.getAttribute('answer');\n";
s += " var menu_link = gel('" + current.sys_id + "link');\n";
s += " if(answer > 1){\n";
s += " menu_link.innerHTML = "" + current.title + "&" + "#60;font color='" + current.u_count_color + "'&" + "#62; (" + answer + ")&" + "#60;/font&" + "#62;";\n";
s += " }\n";
s += " else {\n";
s += " menu_link.innerHTML = "" + current.title + "";\n";
s += " }\n";
if(current.u_refresh_interval){
s += " window.setTimeout('refreshNumber" + current.sys_id + "()', " + current.u_refresh_interval + ");\n";
}
s += "}\n";
All I did was check the answer value and choose which link to write. My purpose in using this was to identify when an error listing had values and displaying zero would make the count link less noticeable over time.
Again, thanks for sharing this. [Oh, and it worked fine in FireFox under Berlin]
Thanks for the feedback! I think this is a great idea. I’ve gone ahead and modified the update set to include this check and make sure that the list contains at least one item before displaying the module count.
We use IE8 at our company, and this had been working great for us until we upgraded to Berlin. Once we did that, I started getting the same bug as others have reported with IE regarding the menu items always being bold. They also wouldn’t “cancel” the previous menu item selected from being bold as well, which I’m not sure was reported by others. I did some experimenting and it appears that the problem is the dynamic creation of the anchor tag. I moved it to a static spot in the span tag and all is now well. My updated “populate” business rule is below.
(There’s also a some style stuff I added in the refresh function which makes the count number always normal font weight, which I think looks better, but that’s neither here nor there.)
//Check to see which filter to apply
countFilter = current.filter;
if(current.u_count_filter){
countFilter = current.u_count_filter;
}
//Make sure default image is used if no image present
var modImg = current.image;
if(!modImg){
modImg = '/images/nav_bult.gifx';
}
if(!/x$/.test(modImg)){
modImg = modImg + 'x';
}
var s = '';
var contextFunc = 'return showModuleContext(event, "' + current.sys_id + '")';
s += ""
s += "<a></a>";
s += "\n";
s += "\n";
s += "refreshNumber" + current.sys_id + "();\n";
s += "function refreshNumber" + current.sys_id + "() {\n"
s += " //Query for the count of records for the module\n";
s += " var count = new GlideAjax('ModuleCount');\n";
s += " count.addParam('sysparm_name', 'moduleCount');\n";
s += " count.addParam('sys_table', '" + current.name + "');\n";
s += " count.addParam('sys_query', '" + countFilter + "');\n";
s += " count.getXML(displayModuleCount" + current.sys_id + ");\n";
s += "}\n\n";
s += "function displayModuleCount" + current.sys_id + "(response){\n";
s += " var answer = response.responseXML.documentElement.getAttribute('answer');\n";
s += " var menu_link = gel('link" + current.sys_id + "');\n";
s += " menu_link.innerHTML = "" + current.title.replace("'", "\'") + "&" + "#60;span style=\\"font-weight:normal;color:" + current.u_count_color + "\\"&" + "#62; (" + answer + ")&" + "#60;/span&" + "#62;";\n";
if(current.u_refresh_interval){
s += " window.setTimeout('refreshNumber" + current.sys_id + "()', " + current.u_refresh_interval + ");\n";
}
s += "}\n";
s += ""
//Set the 'Arguments' field with the script string
current.query = s;
Thanks Brandon! If I can get feedback from a couple of other users that this solution works for them I’ll incorporate it into my update set.
I’m using Firefox and you are right when I tried this in IE8 which we use at work Its Bold…
Ok just found this and it’s absolutely fabulous… I love it thanks.. Anyone ever have any performance issues using this? I am using 1 hour or 30 minutes except for unassigned items.
I haven’t heard of any performance issues reported…especially at those intervals you shouldn’t have any issues.
It may sound obvious, but use a bit of common sense around how heavily you use this. Say for example you have a huge CMDB and you try to do a count of CIs on the navigation. Even with a long refresh period, it is possible to get yourself into a sticky situation.
Some reported that links are showing in bold instead of normal text in some versions of IE. This is because “setAttribute” doesn’t work in IE8. We can fix that by using s += “menu_link.className =’menu’;\n”; in business rule instead of s += ” menu_link.setAttribute(‘class’, ‘menu’);\n”.
I tested this in IE8 and it’s working fine(NO MORE BOLD TEXT ).Hope this information helps u guys!!……………..
Awesome! I just tested and applied the fix to the update set. Thanks for the feedback!
Hmm…I applied this, cleared cache and still see all the bold. I am sure there is something my corp does to the browser.
Yeh I did the same and still bold… I even tried it on our environment that didn’t have it in.
@Ryan and Wendy, make sure that you update the modules as well to see the change. The business rule contains the updated code, but you have to change something in your module definition and save (even if you change it right back) to force the updated html arguments into the module definition. I’ve set this up at the SN demo015 instance if you want to do a quick sanity check there.
Of course! That worked. Sorry I did not think about that.
Ok that worked thanks alot..
Hi guys,
I’ve seen module counts implemented at quite a few customers and love the feature. Now with the tablet interface in Calgary, it brakes the module rendering in the navigator. Any planned updates to support the tablet interface?
Best Regards,
Johan
Thanks Johan. I was unaware of this issue. The real question is whether or not ServiceNow will support their own ‘HTML (From Arguments)’ module type in the tablet interface. The problem is that the tablet navigator doesn’t render the HTML at all, which fundamentally breaks any modules using HTML (including these). You can create a completely new module with regular HTML and see the same thing. I would suggest submitting a support ticket (as I’ve done) and let ServiceNow know of the issue. If you do contact them about the issue, I’d make sure to not mention the Module Counts functionality at all as Support will be quick to dismiss it as my issue. Instead, tell them that the ‘HTML (From Arguments)’ module type is broken in the tablet interface and that they can reproduce it by turning on the out-of-box ‘Tree View’ module under the ‘Knowledge Base’ application. At a minimum, I think they need to allow the ability to designate which modules are for the standard view and which are for the tablet view so that you can at least override the module for tablets. Let me know if you receive any updates from ServiceNow on this. I’ll do the same.
You are right Mark. I should have spent a minute on analysis before submiting my question. 🙂
I’ll push a few buttons on my end and hopefully we can get a fix before GA.
No fix yet, sadly. I will submit something as well.
Anyone had any luck from ServiceNow on this? I have been in love with the module counts, but now that there is more of a push to tablet interfaces, we may have to back out the functionality until a resolve is found.
Unfortunately, ServiceNow isn’t doing us any favors on this one. I just got word back on their “Fix’ for their issue and all they’ve done is prevent the module from being displayed in the tablet UI. Not very useful if you’re dealing with something like ‘My Work’ :). Sometimes the best innovation comes out of frustration though, I’ve managed to come up with a fix that should work in any system from Calgary forward. I’ve uploaded a new version of the update set that you can apply to your instance. Please give it a try and let me know how it goes!
Remember that you’ll have to make an update to any module using the counts functionality for this to work correctly! The end result is a module with counts in the standard interface, and a module without counts in the tablet interface.
Hey Mark,
Where is this new version? I have 1.1 from 11/11 which I am using in Calgary now, and get the same result :(. Is there a newer version than that one? If so, where be it? :).
Thanks for all your hard work, it is so helpful to all of us SNC admins out here!
Sorry, I forgot to update the version number. Latest version is 1.5 and you can get it from the SNGuru downloads page (linked to at the bottom of the article above).
Hello Mark,
at first, thanks a lot for this useful Plugin!
at second, we have some strange issues with the translation.
all modules were successfully translated into german.. except 3.
but if I take a look at the module title, the translation was successfull.
only the module names within the application refuse themselves 🙂
Do you have ever heared about this phenomenon?
regards
Bernd
Yes. Take a look at the previous comments. User language is session related, and this solution generates the module text server-side. Unfortunately Multi-language support isn’t something that the current module counts functionality handles.
Works like a champ! Thanks Mark! Hoping that one day they support the numbers in tablet mode! 🙂
Mark,
Have you looked at this via the the new tablet view released with Calgary (i.e. https://instance.service-now.com/$tablet.do)?
Sadly, the application navigator turns into HTML gobble-dee-gook for any module for which this is applied.
-Joe
I’m aware, and have reported this to ServiceNow support. Take a look at the comment thread above from Johan. It will do this with any module with a type of ‘HTML (From Arguments)’. Actually, it currently just omits the entire module. Hopefully ServiceNow will fix it or give you the option to display modules and applications in the tablet app or not.
Apologies, I missed Johan’s earlier comment. I’ll submit a ticket as well on the HTML (From Arguments) issue. Thanks much.
Cheers.
It would be nice if they would allow us to skip the code if its a mobile interface 🙂
Agreed. It’s really an issue with ServiceNow not supporting their own module type of ‘HTML (from arguments)’. It does look like the new iPad interface just ignores the module in the latest builds (which is better), but they really need some sort of switch so that you can display different modules in the mobile interface if necessary.
CCA 6 still shows code everywhere. I even tried to add the ! isrunningtablet condition and it didn’t prevent it from running the populate counts section. Very strange. I am waiting to hear back from HI now.
Has anyone tried GA (Since wednesday)? I have not had the time.
I have not but here is what i got back regarding the issue.
We have identified existing PRB583655, which is addressing this issue and have related this incident to it. You can track the problem by navigating to: Self Service –> My Problems –> PRB583655. I am going to place this incident in a Pending Problem status and it will get updated as the problem is addressed and solved. The problem is currently targeted for Calgary and our next version.
If you have any further questions or I can be of any further help, please do not hesitate to contact us.
Kind regards,
XXXXXXXXXXX | Technical Support
ServiceNow| Transform IT
First of all this is a great update set – very easy to use. Another idea would be to have it populate the color displayed based on the highest number of priority tickets returned – if 30 records are returned and a majority of them are High then display color would be red, etc…
Thanks for the feedback! I’ve considered that type of setup, but just haven’t got around to implementing it yet. Please let me know if you come up with anything in that area.
They have indeed fixed the issue, its in the next release set from them. I got confirmation of this a week back.
Yes. It is fixed for Dublin and targeted for a fix in Patch 3 for Calgary.
Interesting. Any details on how they fixed it? I’m hoping that it actually renders the module instead of just removing it or something.
Mark,
I have verified it on Dublin, and it just doesn’t render the module. So, a workaround rather then a fix.
Mark,
Do you have an uninstall script for the original? I can’t back out since it’s nearly a year old and since it’s not supported in Dublin I would like to just remove it altogether. I did put in an Enhancement Request for module counts in the Hi system, hopefully that eventually happens.
Thanks!
There is no uninstall script, just as you can’t effectively back out update sets in ServiceNow. Just to be clear though, this functionality is 100% functional in Dublin, just not in the tablet UI. From what I know of the upcoming Eureka and Fiji releases it should still work there as well. ServiceNow has never made any specific announcement about HTML modules being unsupported now or in the future. You can certainly stop using it just by changing those module definitions to standard lists, but you would be disabling a fully-functioning feature needlessly as there’s nothing concrete on the horizon that says it won’t work. I’ve got several customers I know of that are currently using this functionality on Dublin releases with no issue whatsoever.
Johan/Marc – do you have any updates on when the Patch 3 is available for customers? Thanks´!
Sorry Christian, no further date available for Patch 3. If this is hurting, call support and have them investigare and give you an indication.
Thank you for this. We have been using it on Calgary and have mostly had success. We’ve set up a module with the following:
Title: Incident SLA
Table: Incident SLA
Link Type: HTML
Refresh interval: 5 mins
Count color: red
Filter: Business Time left < 4 hrs
Count filter: Business Time left ” or “/>”.
If I change the , then the message goes away. Having done this, the module appears, but with no title.
Do you have any ideas on this please?
Testing this out. Thank you for the continued work, i was a bit disappointed with their resolution as well.
Thanks, I’m glad I was able to develop a workaround. I’ve had several positive reports so far about the fix. Please post back here with your results!
One more update. It looks like ServiceNow plugin activations don’t respect the default values in fields…probably an XML import thing. Because of that, you may have issues where modules in newly-activated plugins or update sets doesn’t display properly. I’ve updated the module counts code to handle this. You can download the latest version…posted just now…to get the fix.
I am not sure if this fix will be a temporary solution since I received this email yesterday from ServiceNow about the removal of HTML in Tablet view:
Hi Chris,
Our problem manager brought this up with our development team, and we received this response:
This is an explicit limitation. We are slowly moving toward limiting the ability to implement free form HTML in the product as this is causing strains to the quality, maintainability and ability to evolve the platform.
So it appears this is part of a larger design goal. I recommend looking for a solution that uses supported modules. I do apologize I this is inconvenient. If you have any questions or concerns about this decision I invite you to reach out to Ben in our problem management team at (858) 876-6552. Given this decision, is it okay to close this incident out?
Regards,
Stuart Gebhardt
Could be, and it doesn’t surprise me but even if that does come along I wouldn’t anticipate it happening in the next couple of releases. I’d say we’ve got a good 2 years at least before this would even be a concern. If they do remove the capability hopefully they’ll add the module counts on their own by then as well.
Hi Mark, Great functionality but can you help with same issue as described above by Matthew Pearson;
We have created a module with a duration filter eg time left is less than 4 days, added the count argument but getting an error displayed on the application menu
Element type “javascript:gs.getDurationDate” must be followed by either attribute specifications, “>” or “/>”.
Can you help??
Hey Roxane,
I’ve looked at this a bit and can’t get the escaping just right. The problem is with the less than or greater than symbols in the filter but they’re not being escaped correctly and no matter what I try I can’t get it to work. If anybody else has a solution I’d love to hear about it and put it in my code.
Couple changes to the “Populate Counts Arguments” Business Rule will fix it. Here’s an updated script that should do it:
popModuleArguments();
function popModuleArguments(){
//Generate a script string to be populated in the 'Arguments' field
//Check to see which filter to apply
var filter = current.filter.toString().replace(/\'/g, '"');
var countFilter = filter;
if(current.u_count_filter){
countFilter = current.u_count_filter.toString().replace(/\'/g, '"');
}
//Make sure default image is used if no image present
var modImg = current.image;
if(!modImg){
modImg = '/images/nav_bult.gifx';
}
if(!/x$/.test(modImg)){
modImg = modImg + 'x';
}
var s = '';
var contextFunc = 'return showModuleContext(event, "' + current.sys_id + '")';
s += "<img src='" + modImg + "' oncontextmenu='" + contextFunc + "'/>";
s += "<span id='modCount" + current.sys_id + "'></span>\n";
s += "<script>\n";
s += "refreshNumber" + current.sys_id + "();\n";
s += "function refreshNumber" + current.sys_id + "() {\n"
s += " //Set the module title and link\n"
s += " var mod" + current.sys_id + " = gel('modCount" + current.sys_id + "');\n";
s += " //Only construct the link if it does not exist yet\n";
s += " if(!gel('" + current.sys_id + "link')){\n";
s += " var menu_link = document.createElement('a');\n";
s += " menu_link.id = '" + current.sys_id + "link';\n";
s += ' menu_link.innerHTML = "' + current.title + '";\n';
s += ' menu_link.title = "' + current.hint + '";\n';
s += " menu_link.href = '" + encodeURI(current.name + "_list.do?" + "sysparm_userpref_module=" + current.sys_id + "&" + "amp;sysparm_query=" + filter + "^" + current.u_sort_order + "&" + "amp;sysparm_view=" + current.view_name) + "';\n";
s += " menu_link.target = 'gsft_main';\n";
s += " menu_link.className ='menu';\n";
s += " menu_link.onclick = function() {refreshNumber" + current.sys_id + "()};\n";
s += " mod" + current.sys_id + ".appendChild(menu_link);\n";
s += " }\n\n"
s += " //Query for the count of records for the module\n";
s += " var count = new GlideAjax('ModuleCount');\n";
s += " count.addParam('sysparm_name', 'moduleCount');\n";
s += " count.addParam('sys_table', '" + current.name + "');\n";
s += " count.addParam('sys_query', decodeURI('" + encodeURI(countFilter) + "'));\n";
s += " count.getXML(displayModuleCount" + current.sys_id + ");\n";
s += "}\n\n";
s += "function displayModuleCount" + current.sys_id + "(response){\n";
s += " var answer = response.responseXML.documentElement.getAttribute('answer');\n";
s += " var menu_link = gel('" + current.sys_id + "link');\n";
s += " if(answer > 0){\n";
s += " menu_link.innerHTML = "" + current.title + "&" + "#60;font color='" + current.u_count_color + "'&" + "#62; (" + answer + ")&" + "#60;/font&" + "#62;";\n";
s += " }\n";
s += " else {\n";
s += " menu_link.innerHTML = "" + current.title + "";\n";
s += " }\n";
if(current.u_refresh_interval){
s += " window.setTimeout('refreshNumber" + current.sys_id + "()', " + current.u_refresh_interval + ");\n";
}
s += "}\n";
s += "</script>"
//Set the 'Arguments' field with the script string
current.query = s;
}
The changes are:
– lines 8, 9, and 11 to replace single quotes returned from the date function with double quotes
– line 37 to encode the URI
– line 48 to encode the URI but also add a function call to decode it from the client side when making the record count Ajax call
There probably needs to be some better replacement code for the quotes but this should work as long as you do not use single quotes in the condition.
Awesome Jim! I just tested this out and it works great. Thanks for helping me figure it out.
I have tested this on the SN demos, but can’t figure out how to enable the counts. Does the code need to be modified to show the counts for each application? I’d like to show the counts for Incidents,
Thanks
You should be able to see the counts from the module form as long as your module type is ‘HTML (from arguments)’. Check out the module form screenshot in the article above and use that as a guide.
Got it. Thanks!
Hi Mark, we recently added these counters to our My Work and My Groups Work modules (as well as a few others) and our Service Desk users absolutely loved it. Unfortunately we realised that any modules with the counters enabled do not appear when using the Calgary iPad interface, which has also been a very popular update recently! Just thought I’d put that out there, not sure how easy it would be to fix. Great work though, would love to know if this has ever been mooted as a product enhancement by SNC?
There’s no way to make them appear in the iPad interface unfortunately. The fact that it works as well as it does is actually a huge workaround from what ServiceNow provides natively. SN actually doesn’t support their own ‘HTML (From Arguments)’ module type in the iPad interface. They simply ignore modules of that type. I’ve created a workaround that puts the module back, but it comes without the module counts when viewing in the iPad. I have no idea on a future SN enhancement but I’m not holding my breath.
Hi Mark,
Great work. Such a great solution. I am really hung up on the language/localization not being available. Would there be a way to only show the counts for en/english only and then for other languages default to the ootb?
For example, you could re-create the ootb sys_app_modules for the other languages. My issue is how would you filter that? Script include? View? Role? Some how in the sys_app_module filter itself with a script include? Possibly only show the one with the html parameters when the current logged in user is in a role dynamically built to include English users?
Im looking for a push in the right direction; got one?? Thanks for your work!
PS: I played around with : var language = gs.getUser().getLanguage();
gs.log(‘language is ‘ + language);
You’re definitely on the right track. You’ll need to manually create duplicate modules for the other language(s) and then use a ‘Before query’ business rule to filter the modules out based on the language of the user accessing the module. These types of business rules are used in several places in ServiceNow so you should have some examples to go off of. I explain how these work in an article here…
https://servicenowguru.wpengine.com/scripting/business-rules-scripting/controlling-record-access-before-query-business-rules/
Thanks for feedback. If I move forward with this solution, I will post the Business rules.
Hi Mark,
I did some small modifications on it, basically I’m applying getMessage() on the current.title, and it works very well for languages/localizations instances. Any special reason not to use it? Should it make performance worse?
Thanks!
That probably works fine for setting the title in the different language, but the problem is that the logic is server-side and is set directly in the module definition. You’re going to need to have multiple modules in order for this to work because none of this logic happens client-side.
I did it calling getMessage() on the client, something like this:
In this way it’s not gs.getMessage (server), it’s getMessage(client), 😉
I also implemented the colors based on the priority of the incidents, if we have any P1, color will be red, if any P2, orange, and if we don’t have P1 or P2, it’s black, I like it 🙂
Awesome! I had completely forgotten that ‘getMessage’ was available client-side. I’ve gone ahead and worked that into the update set. Thanks for the assist!
Not sure if possible or not, but is there any way to make the queue/count perhaps BOLD if something new has come in from the previous refresh? Like a way to know when something new is there… if that makes sense..
It’s probably possible, but not super simple. I don’t have a solution for it currently.
I added the June 2014 version (current as of this comment) in our Dublin instances. After upgrading to Eureka, I could not edit them until I added the fields back to the form that the Eureka upgrade had removed. They continued to function just fine, but they couldn’t be edited, so I couldn’t resave them to remove the old UI11 style module icon until I did this.
Is it possible to use this with an argument-defined list rather than one defined by manual filters? I need to use a script include to build a dynamic query but would like to include a count. Currently using List of Records with no filter defined, just the following in Arguments:
&sysparm_fixed_query=u_ticket_statusIN6,7,8,9^u_user.u_campus_idINjavascript:new getItCampus().getCampus()
I tried entering this in the arguments for HTML with count but after saving it just replaced arguments with the code for the blank filter count.
It is possible. I think the simplest way would be to create a new field on the module form to contain your information. The arguments field has to be used to display the module correctly so I lock it down with module counts to make sure none of the code has to be messed with. If you create a new string field to contain your query then you could customize the ‘Populate Counts Arguments’ business rule to pull that string value as the query instead of anything else if it was present. That will populate the arguments field correctly for you.
Hi Mark
I’ve just implemented the module counts, really like the functionality but I noticed something that could cause it to fall fowl of SN’s code reviews. The script include ModuleCount uses a getRowCount(). Unless there are lots of records in the count then this probably wouldn’t make much difference performance wise but either way I’ve replaced the getRowCount() with a GlideAggregate query, code below.
var ModuleCount = Class.create();
ModuleCount.prototype = Object.extendsObject(AbstractAjaxProcessor, {
moduleCount: function() {
var ga;
ga = new GlideAggregate( this.getParameter(‘sys_table’) );
ga.addEncodedQuery( this.getParameter(‘sys_query’) );
ga.addAggregate( ‘COUNT’ );
ga.query();
return ga.next() ? ga.getAggregate( ‘COUNT’ ) : 0;
}
});
Heads up on another performance gotcha:
Do not set up module counts for modules whose filters include “active=false”.
These data sets by their nature will grow exponentially over time and will cause significant performance issues and spotty outages. Accessing a filtered list on an “as needed” basis is usually fine (although may be sluggish to return). To have users polling back for the same information from the navbar will put unnecessary strain on the DB. Watch out for a more detailed blog post in the ServiceNow Community which will outline these pitfalls in more detail (I’ll post a link when it’s up).
Hi,
I’m new to ServiceNow and we are right now going to ServiceNow from CA Service Desk Manager. This is one of the features Im missing from CA and was really happy when I found you and your page =). Problem for me is that I get an error when I do a preview on the update set and Im to new to understand If it is anything to worry about or not. Se below for a screenshot.
http://sv.tinypic.com/r/4v4rw0/8
That preview issue shouldn’t be a problem. Just go ahead and accept the remote update and it should be fine.
Mark, In Fuji Patch 1, I see a carriage return after the favorite icon placing the module text on a second line. As I recall, I saw this in Eureka UI14 as well. Have you seen this before? Is there a fix for it? Thank you. Bill
There isn’t a fix for it and there’s nothing I can do in this case since it’s ServiceNow’s bug. They’ve started wrapping an extra div around any ‘HTML (from counts)’ module and that’s what’s causing the line break. It used to be an ‘H3’ tag so there wasn’t an issue. There’s an open problem for it, but no word on a fix yet.
Mark, do you happen to have the PRB number from ServiceNow?
Yes, it’s ‘PRB622970’.
Hello.
We were able to get around the Fuji line break issue by adding a CSS property to the populate counts arguments code:
s += “div {display: inline;}\n”;
Hope this helps!
Michael Pierce
Thanks Michael. Can you tell me if you’ve tested this on Eureka as well? Where did you place the code? I’m dropping it right after my closing script tag and it’s not changing anything in my Eureka instance. I haven’t tested your fix in Fuji yet.
Hi
Slightly hacky but fuctional fix for the Fuji issue
Add a new function to the end of the existing set of functions in the Populate Counts Arguments BR
s += “function realignDisplayInline” + current.sys_id + “(){\n”;
s += “document.getElementById(\”modCount” + current.sys_id + “\”).parentElement.style.display = \”inline\”;\n”;
s += “}\n”;
Call the function immediately after the ‘refreshNumber/sys_id/’ function call
s += “realignDisplayInline” + current.sys_id + “()\n”;
This does a DOM walk from the injected SPAN up to the parent DIV (which is the issue as it was added in Fuji) and inserts a ‘display: inline;’ style.
This will require touching the Module items which are using counts as the arguments need to be regenerated.
Only solved this a short time ago but havent had any problems. If I hit any I will update here.
Regards
Adam
Hi Adam, Are you able to post the full script?
I’ve made the changes to the BR but it doesn’t appear to have made any difference on my side. ¯\_(ツ)_/¯
Nick
Hi Adam,
I will also need the full script as my changes to the BR doesn’t appear to make any differnece 🙂
//Tor
Just figured it out. (Thankyou Adam)
I had forgotten we had to re-save the modules are implementing the update to the BR.
So the first 3 lines go before the function call –
“if(current.u_refresh_interval){”
And the final line goes after the closing bracket of the same above mentioned function call.
Then resave the modules and all should work.
Thanks Adam and Nick for assisting with this. I’ve tested this and implemented it in the latest version of the update set. I’ve also simplified the fix a bit. All you need to do is add this line right inside the closing bracket of the ‘refreshNumber’ function in the ‘Populate Counts Arguments’ business rule.
Thanks Mark, brilliant work as always.
Just noticed the code breaks if a module has the refresh interval set to ‘None’.
@Nick, I’m not seeing that. I’ve got it installed in 2 separate instances…one Eureka and one Fuji…and it works fine in either one no matter what the refresh interval is. Are you using the updated code in the update set? If you made the code change manually it might be related to something else.
I had updated it manually, but now reapplying the update set you had posted appears to have corrected the issue.
There seems to be a bit of an issue with the latest update set sys_choice value for sys_app_module.u_refresh_interval
For the choice with a label of “1 minute”, it has a value of “6000”.
Is this value not the equivalent of 6 seconds? Should it not have a value of “60000” instead?
You’re right, this should be 60,000. I’ve updated it in the update set download. The other items you brought up aren’t issues.
Thanks for the update Mark. These deactivated fields still exist on the record and have values. I can see the u_tablet_only field is also being used in the sys_app_module query business rule. But how do I check for issues if I can’t see the value of these fields in the “Show XML” popup window? I am just trying to grasp why you chose to make them deactivated? Is there an advantage I can’t see? Is this just to stop people from being able to modify them without scripting?
That’s exactly why. What we’re doing is creating a duplicate, hidden module record that only shows up in the tablet interface for any module that uses module counts. This had to be done to ensure compatibility with the iPad interface. All of the setup and synchronization of those modules is done behind the scenes so there’s no need to interact with those hidden fields.
So I just downloaded this and got it installed, but I’m having 1 issue so far. If I use javascript:gs.getUserID(); in the filter conditions it breaks the count.
Once I add it, and save the refreshed screen sets the module to List Of Records, and the count no longer works. I have to go back to editing the module from the left nav header, remove that filter to get it working again or at least show back up as an HTML (from Arguments) type.
Also I have a suggestion too – possibility to have thresholds set for multiple colors, what i mean is if the count is >= to a number set a new color. Not a deal breaker, just a suggestion.
Hey Jon, thanks for the suggestion. Regarding your error, I haven’t seen that before. You might try removing the semicolon and see if that solves the issue though.
So it’s a little weird, it seems like it might be something on the save. I did actually try without the semicolon – but I also tried as dynamic and that saved, but refresh showed as List Of Records, and you have to reedit the module to get back to it. But the count seems to still work.
So it’s a slight inconvenience, but still works.
Hey Mark, as a heads up this is very broken in Geneva.
Not only do the counts not display but the links don’t work at all requiring them to be reset to ‘List of Records’
Thanks for the heads up. I just confirmed this. The issue has nothing to do with module counts. The problem is that ServiceNow isn’t properly supporting their own ‘HTML (From arguments)’ module type. I’d advise you to contact ServiceNow support and send them a simple example with any HTML in it. It won’t work because they’re trying to throw all of that HTML into their own HREF tag. Whatever you do, don’t mention module counts or they’ll try to tell you they don’t support 3rd party solutions even though the issue lies with their own code.
Unfortunately I don’t have any other modules using HTML arguments to complain about 🙂
That’s why you should make one. Just create any module of that type and put a simple href tag in there, then use that as the example. It won’t work at all and SN support will have to address the real problem rather than try to place blame on the module counts code. You’re going to have much more success with ServiceNow support if you target the actual source of the problem. There’s absolutely nothing I can do to fix the issue within the module counts code because of the way SN is handling that module type.
Hi Mark,
I have raised an incident with ServiceNow in regards to this as we use HTML from Arguments more than just for this module, and these link back to standard functions which straight away lead to “Page not Found”‘s.
Will keep everyone update with what ever response I receive.
Thank you! I’ll be interested to hear what they say. I raised an incident, it was identified as a bug, and then escalated to a problem. Unfortunately, SN development came back and said that module type wouldn’t be supported in Geneva and going forward. I’d love for them to reverse that decision. Thanks for keeping us posted!
Not able to Download update set, It’s asking me to sign in
Hi Mark,
Please see the below from ServiceNow, in short, they tested it, it didn’t work. Then they did nothing. All they did was advise that my other option was to point to the URL directly using another method.
Hi Robert,
Firstly I must apologise for the time taken to come back to you on this Incident!
You are indeed correct in that the Modules cannot take an argument like that for the HTML (from Arguments) Link Type.
This is documented here:
https://docs.servicenow.com/administer/navigation_and_ui/reference/r_ModuleLinkTypes.html
The recommendation being use the URL (from Arguments) instead.
The following is the Module definition you are enquiring about:
https://<>.service-now.com/sys_app_module.do?sys_id=X
This is the task table Module for My Work and contains: as the argument.
I have been testing in my Geneva instance and this will not work as you have determined
I found another “My Work” module on the task_sla table similarly defined:
https://<>.service-now.com/sys_app_module.do?sys_id=X
This is trying to direct to:
<a href="https:/<>.service-now.com/selfservice/new_incident”>;
This can be updated as below to work correctly:
Link Type: URL (from arguments)
Arguments: selfservice/new_incident.do
Please feel free to ask any further questions here, or if you are happy with this resolution please click the Accept Solution button for this Incident.
Upon acceptance you will receive a short survey to rate our level of service, and if you have the time to complete this we would sincerely appreciate your feedback.
UPDATE:
Unfortunately it is not supported in Geneva, please see:
https://docs.servicenow.com/administer/navigation_and_ui/reference/r_ModuleLinkTypes.html
Specifically:
HTML (from Arguments)
Places HTML in the application navigator. This link type is used for more complicated links, where a flat URL is not customizable enough.
Note:
The HTML (from Arguments) link type is supported in UI15 and UI11 only. In UI16, use the URL (from Arguments) link type instead.
You must enter a value for the Arguments field.
It is also mentioned in the Geneva product documentation for UI16:
https://docs.servicenow.com/release_notes/servicenow_platform/r_UserInterfaceRN.html
If you require certain users to be able to use the link, there are ways to switch between interfaces:
https://docs.servicenow.com/administer/navigation_and_ui/task/t_SwitchBtwnUi16AndUi15.html
Let me add my voice to the sad cry that UI16 dropped support for the HTML (from Arguments) link type. We are going to have a lot of unhappy users when we go live in a few weeks.
We are too 🙁
Hi is this update set still available to download?
Many thanks
Eva
No, it’s not available anymore. ServiceNow has completely crippled the ability to modify the left nav links reliably in the Helsinki release. You’re pretty much locked in to what they provide.
I’ve opened an enhancement — hopefully this will be implemented and soon!
Can we not swap out the HTML Link type for URL link type? we had some links that we had to swap out to URL.
Good idea, but really not that simple unfortunately. If someone can figure out a good way to do this…even with URL-based modules…I’d look at formalizing a solution here again. Unfortunately, I think ServiceNow has just made it way too difficult to do without a serious upgrade impact every time.