g_user object is not defined error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-05-2017 10:12 PM
I am trying to get the current user name in my widget's client script, When I try to use 'g_user.firstName' I'm getting this error g_user not defined in the console.
Can anyone share a sample code to get the current username in client script.
Thanks in advance.
- Labels:
-
Service Portal
-
Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 02:32 AM
is it a Portal widget code? or jelly based?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 03:08 AM
Hi,
If you working on portal widget, then you can fetch the logged in user value such as:
Server Side:- ///Just server side code works and print on HTML such as {{data.sysUserID}}, but if you want to do some work on Client side, then client side code is mentioned
data.sysUserID = gs.getUser().getFullName(); |
Client Side:-
var c = this;
c.server.get().then(function(r) {
c.data.user=r.data.sysUserID});
HTML:- <p>{{c.data.user}}</p>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 04:05 AM
Manikandan Velu wrote:
Can anyone share a sample code to get the current username in client script.
Could you share the code you're writing? Perhaps then people can identify what's causing the error message.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2017 08:54 AM
I've not seen the g_user object work in Service Portal widgets. What I did find is that some user info can be obtained from an object called NOW in the $window service.
There's useful attributes like:
$window.NOW.user_avatar
$window.NOW.user_display_name
$window.NOW.user_id
$window.NOW.user_initials
$window.NOW.user_name
Hopefully this helps you achieve what you need.