function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Phu Dang 1Phu Dang 1 

How do I get the current user login in the Communities website using javascripts?

How do I get the current user login in the Communities website using javascripts?
Avidev9Avidev9
You can just do 

var userId = '{!$User.Id}';


Phu Dang 1Phu Dang 1

@Avldev9 Thank you for the help.  I have SF Communities and would like to add live chat.  In the live chat there is a method that pick up the email address.  Once it picks up the address, it will pull the contact from Salesforce.  Here is the live chat method:  SnapABug.setUserEmail('email@domain.com' (mailto:'email@domain.com')).  Since the login for SF Communities uses email address, I would like to use this email address and pass to the live chat method.  We are using the standard SF Communities webpage.  Is there a way to pass the login from the login page to the the method  above which is in the footer of the SF Communities web page.  Here is the code for the live chat that I put in the footer.
<!DOCTYPE html>
<html>
<body>

<!-- begin SnapEngage code -->

<script type="text/javascript">
 
 (function() {
 
  var se = document.createElement('script');
 se.type = 'text/javascript'; se.async = true;
 
  se.src = '//commondatastorage.googleapis.com/code.snapengage.com/js/cf7f5802-c6c9-44c5-855b-6c25f47ea721.js';
 
   var done = false;
 
  se.onload = se.onreadystatechange = function() {
  
   if (!done&&(!this.readyState||this.readyState==='loaded'||this.readyState==='complete')) {
 
 done = true;
 
 /* Place your SnapEngage JS API code below */
 
SnapABug.setUserEmail(username);  
 /* SnapEngage.allowChatSound(true); Example JS API: Enable sounds for Visitors. */
 
   }
  
 };
  
 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(se, s);
 
 })();
</script>
<!-- end SnapEngage code -->
</body>
</html>