- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2019 06:11 AM
Hi, I wonder if anyone has run into this issue?
I'm trying to preload user preferences so they are available for client scripts without having to call:
getPreference('pref_name');
If you run this function from browser dev tools (F12), you get the following message appear in the console:
"Preference pref_name not found in the active user cache. Making a blocking AJAX call to load it. Consider pre-loading this property in glide_user."
I cannot find any documentation on how you can preload a user preference, I'd like to avoid making synchronous ajax calls if possible.
Can anyone shed any light?
Many thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2019 05:58 AM
So the goal is to redirect them to a survey if they haven't taken one yet? Is this a one time thing or will it happen based on multiple surveys?
I think instead of trying to run something on every page you could just add a login rule or modify an installation exit to redirect them to the survey on login if they need to take it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2019 06:59 AM
You can make a server side call to add data to the user's session using putClientData(), then access it client side with getClientData().
The way I've seen this done most often is with a script action that runs off the user login event and adds data to the user's session.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2019 08:26 AM
Many thanks Brad.
I originally started off using session data, however g_userclientData isn't available on any pages which are like dashboards or cms pages. So I can't perform the checks I need to on my UI script on every page load. Just on forms or lists unfortunately.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2019 08:38 AM
I think your question was around preloading user preferences based on that error message, and I'm pretty sure that's what it's referring to. If you need access on CMS pages then you'll need to load the g_user object or a ui script manually on those pages.
What is your overall requirement? Maybe there is a different way to achieve it than needing session data on every page?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2019 05:48 AM
Hi Brad,
So basically I have a requirement to check whether or not users have been through an attestation (just a survey), if they have they will be added to a special group to get the itil role.
My logic starts off with a script action which triggers on the session.established event.
The script checks if the user has the itil role.
The script then needs to set a parameter to send to the client to say if the user has the role or not (session data or preference).
The parameter is then checked in a ui script.
If the param is true, the user is directed to complete the survey.
If it's false, nothing happens.
I'm trying to avoid making ajax calls if possible.
Hope that helps to clarify a bit.
Thank you.