Jump to content


Get username with custem.js

Started by Martin Dijkhuizen , 02 August 2017 - 09:13 PM
2 replies to this topic

Martin Dijkhuizen Members

Martin Dijkhuizen
  • 2 posts

Posted 02 August 2017 - 09:13 PM

Hi All,



I'm playing arround with de inetpub/citrixweb/custom/custom.js file and used the default example as posted below and I'm wondering if I can get the logged in username because the CTXS.Extensions.beforeDisplayHomeScreen is running after I'm logged in.



My intention is to get the username and put the username in a client session cookie so another part of a intranet site can read this cookie and knows that the user is logged in and give the user his extra menu items. The reason I'm trying it this way is because we embedded the storefront as a iframe in our intranet. 

I searched the internet for a good example but I couldn't find one.
CTXS.Extensions.beforeDisplayHomeScreen = function (callback) {
    if (!doneClickThrough) {
            messageTitle: "Welcome!",
            messageText: "Only for WWCo Employees",
            okButtonText: "Accept",
            okAction: callback
    } else {


Thanks in advance for your input.


With kind regards,



Christopher Chafe Members

Christopher Chafe
  • 2 posts

Posted 08 August 2017 - 08:59 PM

I also would like to customize by user. I found the following functions, but they don't seem to return anything:





Trentent Tye Members

Trentent Tye
  • 60 posts

Posted 13 August 2017 - 06:09 AM

Each of those functions operates asynchronously, so you need to plan for that.  Doing the request won't respond immediately.


I created a function that returns the username in a synchronous way (NOT GOOD FORM!) as I need the username at a specific point in time:

function getUsername () {

See Get User Name
var usernameURL = CTXS.Config.getConfigValue("authManager.getUsernameURL");
var result = "";
ajaxWrapper({ type: "POST", async: false, url: usernameURL, dataType: "text", success: function (data) {
CTXS.trace("getUsername data:" + data);
result = data;
return result;



You can add this function to your custom.js and it will work.  Since it's operating synchronously it will pause your web session while these details are worked out.  You can probably avoid it if you code properly and use promises if your just doing GUI stuff and timings are not important.


From here: