check if user is logged in from UI script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2015 11:54 AM
I have a CMS site where I need to hide html elements on various pages if the user is NOT logged in. I propose to do this in a global UI script but can't figure out how to check if the user is logged in; i.e., g_user will not work. Does anyone know or have an alternative?
I know global UI scripts are not a preferred method but how else would you check client side for the page name, if user is logged in, and hide elements?
I have a cms page that is a menu page with a catalog request for field so I cannot specify a particular table in a client script.
Code examples and suggestion would be much appreciated.
Thank you!
- Labels:
-
User Interface (UI)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2015 12:07 PM
Here is what I had done previously to get a users id
UI Script
userCheck();
function userCheck(){
var ga = new GlideAjax('CheckUser');
ga.addParam('sysparm_name','u_user');
ga.getXMLWait();
alert(ga.getAnswer());
// HERE IS WHERE YOU WOULD WANT TO CHECK IF THE USER IS EMPTY
}
Script Include
Name: CheckUser
Client Callable: Checked
var CheckUser = Class.create();
CheckUser.prototype = Object.extendsObject(AbstractAjaxProcessor, {
u_user: function() {
return gs.getUserID();
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-11-2015 12:37 PM
Great idea but the userid comes back null or undefined even when I'm logged in. Did this ever happen to you? It looks like it should work.
Kathy Chisefsky
Web Developer
ActioNet, Inc.
20300 Century Boulevard, Suite 200
Germantown, MD 20874
Phone: 301-944-5681
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2015 04:22 AM
Im sorry, in line 4 of the script include there is an error.
it should be
return gs.getUserID();
I have edited it in my above comment as well
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2016 12:39 PM
Hey Alex,
I tried this script, but it returns 'null' value. Can you please check?
Thanks