cancel
Showing results for 
Search instead for 
Did you mean: 

Resetting user dashboards using web script

cybertoast
Champ in-the-making
Champ in-the-making
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 cmSmiley Tongueerson), 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?
1 REPLY 1

mikeh
Star Contributor
Star Contributor
The wiki article relates to dashboards in the Explorer (JSF) client world, not Share.

Unfortunately there isn't a wiki article for the Share dashboards, so you need to take a look at the customise-dashboard.post.js code (in site-webscripts/org/alfresco/components/dashboard) to see what's going on.

Thanks,
Mike
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.