- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-23-2015 07:47 AM
Hello Community,
I'm trying to utilize a UI Script to generate a popup for end users. As I understand it, a UI Script utilizes Client Side scripting. However, I cannot seem to get it to return GlideRecord results. I've done something simple like...
var id = g_user.userID;
alert("User is : " + id);
This will not generate an alert. So I thought maybe UI Scripts utilize Server Side scripting so I changed that script to...
var id = gs.getUserID();
alert("User is : " + id);
So at this point i'm really confused as to why I can't get any results. So I resorted to GlideAjax and a Script Include to test and it turns out the GlideAjax actually does give a popup, but it's always "undefined".
var ga = new GlideAjax('KnownIssueAjaxScript');
ga.addParam('name', 'userPreference');
ga.getXML(ScriptParse);
function ScriptParse(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
}
The above script is the GlideAjax I used in the UI Script. Below is the Script Include I called to...
var KnownIssueAjaxScript = Class.create();
KnownIssueAjaxScript.prototype = Object.extendsObject(AbstractAjaxProcessor, {
initialize: function() {
},
userPreference: function(){
var name = "Walk this way!";
return name;
},
type: 'KnownIssueAjaxScript'
});
Here is what I am trying to accomplish.
GOAL : Generate a popup message for all users. Once the user acknowledges the popup message, they shouldn't get the popup anymore.
My approach was to create a global script that I can enable which will in turn, create a GlideOverlay or GlideDialogWindow to display a popup UI Page containing a message to users. When the users click a button that will be on the popup UI Page, it will update a user preference so that the popup doesn't keep coming up for that user. (Similar to what happens with the OOB UI14 pop up message.)
Any ideas or suggestions?
Solved! Go to Solution.
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2015 01:17 PM
Hi Kenneth,
On the Client Side, you can use getPreference('name of user preference') and setPreference('name or user preference', 'value of preference) to handle user preferences. So for example:
addLateLoadEvent(function() {
// getPreference returns an empty string if there is no property yet. Once the property is set, the if statement will be false
if (getPreference('showUserAlert') == '') {
var id = g_user.userID;
alert("User is : " + id);
setPreference('showUserAlert', 'true');
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-09-2017 04:04 PM
Hi Phillip,
The code looks fine to me without actually plugging it into one of my instances. From the symptoms you are describing, it sounds like a caching issue more than anything else. With ServiceNow, there is a lot of caching going on especially with properties and preferences. The best recommendation that I have is to clear the server cache (navigate to the cache.do page) and clear / override your browser cache when you make property and preference changes. If you are still getting the same results after clearing caches, let me know and I will take a deeper look at it.
Kind regards,
Travis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2015 09:35 PM
If its preferences you are after they can be accessed with OOB functions both on client and server. See this blog,
ServiceNow User Preferences - Server and Client Access-John Andersen
Also, keep in mind the g_user object is available on every page. Like the homepage or workflow page.
Another idea for your requirements, look here.
Session Client Data - ServiceNow Wiki
May be able to utilize session storage instead of a preference.