cancel
Showing results for 
Search instead for 
Did you mean: 

Get properties of a node

sihnu
Champ in-the-making
Champ in-the-making
Hi, I stumbled on a weird problem recently. I use lucene search to search for all the nodes that have aspect Complianceable. I can find the nodes I'm looking for but for some reason all values of the properties I can get from those nodes are their names. Like here:

var isCompAdded = "ASPECT:\"{http://www.alfresco.org/model/content/1.0}complianceable\"";

var searchQuery = isCompAdded;

var results = search.luceneSearch(searchQuery);

for(var i=0; i<=results.length; i++)
{
if(results[i] != null)
{
log += "File Name:" + results[i].properties.name + "\n";
}
}

But if I try to refer to any other property that node has I get the following error:

org.alfresco.scripts.ScriptException: 03290000 Failed to execute script 'workspace://SpacesStore/6b12ff23-fc8e-451e-b860-17e14f723a1a': Node does not exist: workspace://SpacesStore/45560937-a9a9-496d-a04a-ba3cf674260f

For example if I try to get a value of property removeAfter like here:

for(var i=0; i<=results.length; i++)
{
if(results[i] != null)
var removeDate = results[i].removeAfter;
{
log += "File Name:" + results[i].properties.name + "remove date:  " + removeDate + "\n";
}
}

I've tried all:

results.removeAfter;
results.properties["cm:removeAfter"];
results.properties.removeAfter;


But they all give the same error. I've checked from the log that names of the nodes are correct ones and those nodes have also a property removeAfter. I've also  tried other properties like cm:created but that gives the same error. How shoudl I refer to the property of the node so I could get the value?

Any help would be appreciated  Smiley Happy
1 REPLY 1

sihnu
Champ in-the-making
Champ in-the-making
Hmm… for testing purpose I created this script and a rule to run the script everytime the document gets updates if the document has aspect Complianceable and it runs fine!

var log = "Script Excecuted For complianceable aspect (remove after) work? \n\n";
var logFile = companyhome.childByNamePath("complianceable_log.txt");
var presentDate = new Date();
var docRemoveDate;

if (logFile == null)
{
logFile = companyhome.createFile("complianceable_log.txt");
}

if (document.properties["cm:removeAfter"] < presentDate)  {
   log += presentDate + "File Name:" + document.properties.name + "\t" +"Remove Date:" + document.properties["cm:removeAfter"] + "\n";
   document.remove();
}

logFile.content += log;

Exception is that this script is not part of the scheduled action like the other one. Anyway, here I can refer to the properties of the node. It's so weird it's not wokring in my other script. To clarify here is the the script as whole that I'm trying to get working:

var log = "Script Excecuted For complianceable aspect (remove after) work? \n\n";
var logFile = companyhome.childByNamePath("complianceable_log.txt");
var presentDate = new Date();
var docRemoveDate;

if (logFile == null)
{
logFile = companyhome.createFile("complianceable_log.txt");
}

var isCompAdded = "ASPECT:\"{http://www.alfresco.org/model/content/1.0}complianceable\"";

var searchQuery = isCompAdded;

var results = search.luceneSearch(searchQuery);


for(var i=0; i<=results.length; i++)
{
   if(results[i] != null)
   {
      if(results[i].properties["cm:removeAfter"] < presentDate)
         log += presentDate + " File Name:" + results[i].properties.name + "\t" +"Remove Date:" + results[i].properties["cm:removeAfter"] + "\n";
         results[i].remove();
   }
}

logFile.content += log;