Planned maintenance is scheduled for the week of June 15th - the exact date and time will be announced soon.
See More Details
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
RE: themeDisplay.getUserName() is not working in javascript
Varun Gupta, geändert vor 6 Jahren.
New Member
Beiträge: 2
Beitrittsdatum: 27.11.19
Neueste Beiträge
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.
Olaf Kock, geändert vor 6 Jahren.
Liferay Legend
Beiträge: 6441
Beitrittsdatum: 23.09.08
Neueste Beiträge
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?
Varun Gupta, geändert vor 6 Jahren.
New Member
Beiträge: 2
Beitrittsdatum: 27.11.19
Neueste Beiträge
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, geändert vor 6 Jahren.
Liferay Legend
Beiträge: 6441
Beitrittsdatum: 23.09.08
Neueste Beiträge
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.
Kailash Yadav, geändert vor 6 Jahren.
Regular Member
Beiträge: 211
Beitrittsdatum: 18.10.11
Neueste Beiträge
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);
Community
Company
Feedback