Identify Logged In User
GlobalSearch uses a cookie to store the logged in user for the current session. For any number of reasons, you may wish retrieve that user’s login name. Using a Live Field, that data can be easily accessed and become accessible.
The sample code below demonstrates reading the cookie and isolating the value of the authenticatedUser key contained within it.
let crumbs = document.cookie.split(';');
for(let i = 0; i < crumbs.length; i++) {
let c = crumbs[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf("authenticatedUser") == 0) {
let user = c.substring("authenticatedUser".length+1, c.length);
alert(user);
return user;
}
}
return 'Unable to collect user from cookie.';
The output of this example will create a browser alert window containing the users name. The name will also be returned to the value present in the Live Field itself. It is worth noting that the value in the Live Field is for presentation only and is never stored. If you need to store any value, it should be written to a standard field type and saved.