Message Boards
themeDisplay.getUserName() is not working in javascript
Varun Gupta, modified 3 Years ago.
themeDisplay.getUserName() is not working in javascript
New Member Posts: 2 Join Date: 11/27/19 Recent Posts
Hello All,themeDisplay.getUserName() is not working properly in javascript. It is giving ASCII string. Please refer screenshot.
Is there any other way to get userName in javascript or I have to make service call to get userName?Thanks in advance.
Is there any other way to get userName in javascript or I have to make service call to get userName?Thanks in advance.
Attachments:
Olaf Kock, modified 3 Years ago.
RE: themeDisplay.getUserName() is not working in javascript
Liferay Legend Posts: 6396 Join Date: 9/23/08 Recent PostsVarun Gupta:
Hello All,themeDisplay.getUserName() is not working properly in javascript. It is giving ASCII string. Please refer screenshot.
Is there any other way to get userName in javascript or I have to make service call to get userName?Thanks in advance.
It looks like the user you took the screenshot with is named "Test Test" - "\u0054\u0065\u0073\u0074\u0020\u0054\u0065\u0073\u0074" is the Unicode encoding of that string, so the result comes in an unexpected encoding, but it's there. Which (exact) version are you on?
Varun Gupta, modified 3 Years ago.
RE: themeDisplay.getUserName() is not working in javascript
New Member Posts: 2 Join Date: 11/27/19 Recent Posts
Hi Olaf,Thanks for the reply.I am using Liferay 7.2 Sp1 EE. I am trying to get username in main.js and it is returning unicode value for username. It should give proper username instead of Unicode string.
Thanks..
Thanks..
Olaf Kock, modified 3 Years ago.
RE: themeDisplay.getUserName() is not working in javascript
Liferay Legend Posts: 6396 Join Date: 9/23/08 Recent PostsVarun Gupta:
Being on DXP 7.2 SP1 (there's no more EE, just DXP vs CE) makes this a great quick description for filing a ticket with the support team.
Hi Olaf,Thanks for the reply.I am using Liferay 7.2 Sp1 EE. I am trying to get username in main.js and it is returning unicode value for username. It should give proper username instead of Unicode string.
Kailash Yadav, modified 3 Years ago.
RE: themeDisplay.getUserName() is not working in javascript
Regular Member Posts: 211 Join Date: 10/18/11 Recent Posts
Hi Varun,You can get user name in javascript as following :
var r = /\\u([\d\w]{4})/gi;
var userName = themeDisplay.getUserName().replace(r, function (match, grp) {
return String.fromCharCode(parseInt(grp, 16)); } );
console.log(userName);
var r = /\\u([\d\w]{4})/gi;
var userName = themeDisplay.getUserName().replace(r, function (match, grp) {
return String.fromCharCode(parseInt(grp, 16)); } );
console.log(userName);