AnsweredAssumed Answered

[javascript] children property of created space is null

Question asked by stijndereede on Nov 13, 2007
Latest reply on Nov 14, 2007 by stijndereede
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: " +;
  logger.log("incoming 2: " +;
  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\': Failed to execute script 'D:\alfresco220dev\tomcat\webapps\alfresco\WEB-INF\classes\alfresco\extension\templates\webscripts\cayman\': 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 gives a null pointer exception in both cases (line 42), as does["cm:contains"].length.

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