AnsweredAssumed Answered

Resetting user dashboards using web script

Question asked by cybertoast on Dec 2, 2009
Latest reply on Dec 2, 2009 by mikeh
I'm using the code in the User Configurable Dashboards wiki page, and running into a problem.

The code finds all the available users (using luceneSearch for cm:person), then traverses this list and resets the preferences for each user. The traversal works fine, but when it gets to ..

         if (preferences.properties["app:dashboard"] != null)

.. this always returns null. Even for a user who has customized their dashboard. So what happens is that nothing is ever cleared since Alfresco thinks that there is no dashboard preference set.

I set this up as follows:
1. Create resetdashboards.get.js, resetdashboards.get.desc.xml, resetdashboard.get.html.ftl as follows (in Data Dictionary > Web Scripts > org > alfresco > sample):
resetdashboard.get.js

var people = search.luceneSearch("TYPE:cm\\:person");

var notes = [];

for each (p in people)

{

   logger.log("Found user: " + p.properties.userName);

   notes.push("Found user " + p.properties.userName);

   if (p.hasAspect("app:configurable"))

   {

      var config = p.childAssocs["app:configurations"][0];

      var prefs = config.childrenByXPath("app:preferences");

      if (prefs.length == 1)

      {

         var preferences = prefs[0];

         if (preferences.properties["app:dashboard"] != null)

         {

            preferences.properties["app:dashboard"] = null;

            preferences.save();

            logger.log(" preferences found and cleared.");

            notes.push("Cleared dashboard for " + p.properties.userName);

         }

      }

   }

}

model.notes=notes;
resetdashboard.get.html.ftl

<html>
  <head>
    <title>Reset Dashboards</title>
  </head>
  <body>
    <p> If everything worked users' dashboards should be reset to default. <a href="/share">Check yours out</a>.</p>
    <p>Notes:</p>
    <ul>
<#list notes as note>
       <li>${note}</li>
</#list>
    </ul>
  </body>
</html>
resetdashboard.get.desc.xml

<webscript>
<shortname>Reset User Dashboards</shortname>
<description>Revert all user dashboards to preset-based default</description>
<url>/sample/resetdashboards</url>
<authentication>admin</authentication>
<transaction>required</transaction>
</webscript>

I ran this using the alfresco javascript debugger, and I can see as I step through the code that I never get anything other than null for preferences.properties["app:dashboard"]. I'm running this is as the admin user.

Any ideas on what I might be doing wrong?

Outcomes