Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
themeDisplay.getUserName() is not working in javascript
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:
Varun 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?
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..
Varun 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.
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);
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™