cancel
Showing results for 
Search instead for 
Did you mean: 

[javascript] children property of created space is null

stijndereede
Champ in-the-making
Champ in-the-making
I'm trying to upload files with the upload script to a space I created (Incoming Files). I want to know how many children this space already has, so I can generate a unique prefix to avoid double names.
However, I get a null pointer exception when I try to access the children property of the space I created. I can access the children property of already existing space with no problem (eg Guest Home). See he code below:

  incoming1 = companyhome.childByNamePath("Guest Home");
  incoming2 = companyhome.childByNamePath("Incoming Files");
  logger.log("incoming 1: " + incoming1.properties.name);
  logger.log("incoming 2: " + incoming2.properties.name);
  logger.log("incoming 1 children: " + incoming1.children.length);
  logger.log("incoming 2 children: " + incoming2.children.length);

This gives the following output:

16:33:34,919 DEBUG [org.alfresco.repo.jscript.ScriptLogger] incoming 1: Guest Home
16:33:34,929 DEBUG [org.alfresco.repo.jscript.ScriptLogger] incoming 2: Incoming Files
16:33:34,939 DEBUG [org.alfresco.repo.jscript.ScriptLogger] incoming 1 children: 2
16:33:34,939 DEBUG [org.alfresco.repo.jscript.RhinoScriptProcessor] Time to execute script: 101ms
16:33:34,939 INFO  [org.alfresco.web.scripts.DeclarativeWebScript] Caught exception & redirecting to status template: Failed to execute script 'D:\alfresco220dev\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\extension\templates\webscripts\cayman\upload.post.js': Failed to execute script 'D:\alfresco220dev\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\extension\templates\webscripts\cayman\upload.post.js': Wrapped java.lang.NullPointerException (AlfrescoScript#43)
The null pointer exception is at line 43, which is: logger.log("incoming 2 children: " + incoming2.children.length);

Accessing incoming.properties.children.length gives a null pointer exception in both cases (line 42), as does incoming.properties["cm:contains"].length.

This is all inside the upload.post.js script, which works fine except or this.


Stijn
1 REPLY 1

stijndereede
Champ in-the-making
Champ in-the-making
After deleting the whole repository (drop and create database, delete storage directory) the children property works again. Strange….