The Session Stack
Many, many thanks to Chris Czerniak and Orlando Carattini at Service-Now for this one.
One of the really handy features of Web Servers is the ability to take a value and place it into memory.
The value is then maintained in memory for the life-cycle of the request, session or application.
So how does this play into Sevice-Now?
First a little history. My company has a lot of integration with various systems. To assist the business process, we expose “external links” in the left-hand nav menu through Service-Now for these integrations.
We are a MSP of MSPs. We brand our services for our customers. One aspect of this branding is showing the customers of our customers a unique view to Service-Now and these external systems.
This branding is done via URL, so the menus within Service-Now need to point to a different URL for each MSP we service.
We originally wrote a function in a script include that looked up the user’s company and domain and returned the url for that domain. The problem with this is each menu item rendered sucks up about 0.7 seconds to make the call to the function, do the various queries and return a result. There are 16 menu items, so it took about 11.2 seconds to render the external menus alone.
Here’s where this next tid-bit comes in handy, the user preference stack.
When you log into the system, your user preferences are stored in the session stack.
This is the object that is returned by gs.getUser() in your scripts.
The interesting thing about this object is that it can be manipulated.
Here is a sample script for user preferences. You can test it in scripts background.
//set a preference for current session id
gs.getUser().setPreference("test","hello Current User");
gs.print(gs.getPreference("test"));
Now back to my dilemma. 11.2 seconds is a terrible experience to the users of the system.
I needed to make the screen load faster. Since the value returned from the function was the same for each menu, it made sense to put that value in memory on the first run then just pull it from memory for each subsequent runs.
Wouldn’t you know, I took that load time from 11.2 seconds, down to 2 seconds.
https://glassputan.wordpress.com/2013/01/21/the-session-stack/