Refresh the Left Navigation Pane via Script

Here’s a quick scripting tip for today. Have you ever needed to refresh the left navigation menu in response to some script action? I don’t think this requirement comes up often, but I just had somebody ask me a question related to this so I figured I would find out how it can be done.


The code below is taken directly from a ServiceNow demo instance, and you can find it in your own instance as well. The server-side example comes from a business rule on the ‘sys_app_module’ table, and the client-side example comes from digging around in the DOM. :)

Server-side refresh trigger

–For use in business rules, UI actions, etc.

// tell the UI to refresh the navigator
var notification = new UINotification('system_event');
notification.setAttribute('event', 'refresh_nav');
notification.send();

Client-side refresh trigger

–For use in client scripts, UI policies, etc.

getNavWindow().location = 'navigator_change.do';

 

For another way to use UI Notifications, take a look at our article Display Messages With UI Notifications.

Date Posted:

May 22, 2012

Share This:

9 Comments

  1. William Sun May 22, 2012 at 1:34 pm

    Any chance we might get the other part of this code? I have actually been trying to get this number to appear beside the link where it actually shows how many active items are on that list. {in reference to the number “64” to the right of “Open” on the image}

  2. William Sun May 23, 2012 at 7:39 am

    Exactly, thanks Jim.
    I will definitely be adding this to my instance.

  3. John Edwards July 25, 2013 at 3:00 pm

    I’m looking for a way to force a refresh for all users when I add or remove a nav pane option as part of releasing enhancements. How would this be adapted for such a purpose? I’d like to ensure that all the users are using the same nav pane.

    • Mark Stanger July 25, 2013 at 5:15 pm

      This would make up a VERY small portion of such a solution. Proactively updating information in the user’s browser requires a decent amount of scripting and GlideAjax to call back to the server periodically to refresh. It can be done, but it’s actually a fairly challenging scripting setup consisting of a UI script and a Script include at a minimum.

      • John Edwards July 26, 2013 at 7:18 am

        Thanks for the reply, Mark. I was hoping this would be an easy solution. It looks like I’ll have to put that idea on the back burner for a while.

  4. Russell Miller October 8, 2013 at 5:09 pm

    Hi Mark,

    I’m interested in UINotification(), it seems to be an undocumented feature. Do you know any more about it?

    • Mark Stanger October 8, 2013 at 5:11 pm

      It is undocumented and I don’t know anything about it aside from this particular function unfortunately. You’ll probably need to go to ServiceNow support to get a good answer on it. If you discover anything, please let me know so that I can post it.

Comments are closed.

Categories

Tags

Loading

Fresh Content
Direct to Your Inbox

Just add your email and hit subscribe to stay informed.