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.
thumbnail
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..
thumbnail
Olaf Kock, geändert vor 6 Jahren. Liferay Legend Beiträge: 6441 Beitrittsdatum: 23.09.08 Neueste Beiträge
Varun Gupta:

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.
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.
thumbnail
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);