Script to extract user properties

Question: How do I retrieve the properties of current user?
Answer: The following script (serverside Javascript in the SiteVision Script portlet) demonstrates the solution

// Get utilities in the SiteVision Public API
var utils = request.getAttribute("sitevision.utils");
var propertyUtil = utils.getPropertyUtil();
var ctxUtil = utils.getPortletContextUtil();

// Get current user
var user = ctxUtil.getCurrentUser();

out.println("<table style=\"border:1px solid black\" summary=\"\">");
out.println("<caption>JCR properties for current user</caption>");

// Iterate user properties
var allPropertiesIterator = user.getProperties();
while(allPropertiesIterator.hasNext())
{
   out.println("<tr>");    
   try
   {
      var property = allPropertiesIterator.nextProperty();
      var pName = property.getName();
      var pValue = propertyUtil.getString(user, pName, "null");

      out.print("<th>" + pName + "</th>");
      out.print("<td>" + pValue + "</td>");
   } catch (e)
   {
      out.println("Exception occurred: "+ e)
   }
   out.println("</tr>");    
}
out.println("</table>");

Denna sida publicerades: 2016-11-14

Skriv ut PDF-avsnitt

Hjälpte informationen på den här sidan dig?

Missa inga nya rön, tips och tricks! Prenumerera på insite!

Find us!

SiteVision AB (Headquarter)
Vasagatan 10
702 10 Orebro
Sweden

Info: +46 19-17 30 30
Support: +46 19-17 30 39

Latest Tweets