How to use gs.getSession() functions for other users?

mkhan123
Kilo Contributor

We already have a script that cache certain items on our CMS portal. I am going to design a UI Action (button) on sys_user form. Clicking this button should do the following and clear the portal cache for that particular user. The problem is that I am unable to run this code for other users as these functions are related to current logged in user.

 

gs.getSession().clearClientData(CachedItem_1);

gs.getSession().clearClientData(CachedItem_2);

gs.getSession().clearClientData(CachedItem_3);

10 REPLIES 10

Currently, our CMS portal has multiple elements that are cached. Having the user log off/on does not clear this usually. We need to do something per user or per company where we can force the portal to clear cache on demand. When the portal was built, to reduce server load, we implemented caching to reduce server load. So users by default are looking at a cached view. Anytime we make form modifications, the cache needs to be cleared for the user or for the entire company. For example, a button/checkmark that forces cache clearing for a couple days, or set something for each user.


Mwatkins
ServiceNow Employee
ServiceNow Employee

If the cached item isn't reset by logging in and out, then it will not be reset by doing gs.getSession().clearClientData(Company); Session data stored in this manner cannot possibly persist after a user logs out.



Browsers routinely cache things like images, CSS files, and other page resources. The browser determines that it has already seen some file based on the name or origin. This would explain why some elements do not change even after a user logs in and out of ServiceNow. One thing that could be done is to change the name of the resource itself. Then the browser would definitely need to refresh with the new modifications. Could use some kind of date based string to put on the end of the resource name?


Hi Matthew...Could you please explain what you mean by changing the resource name?


Mwatkins
ServiceNow Employee
ServiceNow Employee

I'm assuming you have a resource like acme_logo.png for the logo of company ACME. Then you have some configuration where you set ACME logo = acme_logo.png. When the users from company ACME log in the system says, "This customer is from ACME, they should see acme_logo.png".



Now the user's browser caches any file named mohd.service-now.com/images/acme_logo.pngx



If you make a change on the backend and upload a new image with the name acme_logo.png then even though you have made a change to the image it would not be reflected in user's browser because they have cached the earlier picture.



However, if at the time that you make a change to the ACME logo you also change the name of the image that is used to acme_logo20170321131427.png then the browser will not have a file with that name cached and the fresh image will be used.


Hi Matthew...Your assumption is right but I don't think we will change names. We still need a way to clear the items in cache which were cached explicitly. We do have a clearCache() function in a script include which is called when the current logged in user change the language from language drop down and the page is reloaded. We just need a way to execute this same function for other users.