- 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
‎02-23-2015 08:01 AM
Hi Kenneth,
You are correct that UI Scripts are client side. To take your initial script, here is something to try:
addLateLoadEvent(function() {
var id = g_user.userID;
alert("User is : " + id);
});
The addLateLoadEvent is an undocumented function client side but it is an essential one. Most of the ServiceNow client API is not available when the page first loads or when your UI script runs. The addLateLoadEvent adds a function that takes no parameters to a list of function callbacks to run after ServiceNow has sufficiently loaded the client side APIs and forms. You should be able to adapt that function using getPreference and setPreference functions. If the preference is false, don't show the alert. When the user confirms the alert, set the preference. If you need more assistance on this one, please let me know.
Kind regards,
Travis
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-24-2015 08:20 PM
Alright Travis,
I've managed to get several pieces into place and now i'm trying to get the user preference functionality in place. So how does that work exactly? Would I do something like gs.getUser.getPreference('preference_name', 'default_value') to determine if the preference is set or not. If not, i'm' guessing I would use something like gs.getUser.setPreference('preference_name', 'new_value')?
- 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
‎02-25-2015 01:20 PM
Travis,
I actually started off using this method but that sys_user_preference table takes a little longer to update than I have time for with this particular pop-up. I did manage to get it working though. Thanks for the help.