cancel
Showing results for 
Search instead for 
Did you mean: 

Webscript controller : Just a misunderstood about null value

zomurn
Champ in-the-making
Champ in-the-making
Hi,

I'am currently debugging a webscript (not of mine) turning on all debugging features for web script in alfresco, more precisely a controller named categories.get.js ; here a portion of code of it :

for(var i = 0; i < categories.length; i++) {
      var result = connector.get("/deckshare/categoryChildren/path/"+categories[i]);
      logger.log("result1"+result==null);
      logger.log("result2:"+result=='null');
      logger.log("result3:"+result=="null");
      if(result != null && result != "") {
         logger.log("result="+result);
                        …
                }
}

And the output result is :

16:29:08,697 DEBUG [org.alfresco.repo.jscript.ScriptLogger] false
16:29:08,697 DEBUG [org.alfresco.repo.jscript.ScriptLogger] false
16:29:08,697 DEBUG [org.alfresco.repo.jscript.ScriptLogger] false
16:29:08,697 DEBUG [org.alfresco.repo.jscript.ScriptLogger] result=null
16:29:08,699 ERROR [org.springframework.extensions.webscripts.AbstractRuntime] Exception from executeScript - redirecting to status template error: 00180003 Failed to execute script 'org.springframework.extensions.webscripts.ResourceStore$WebApplicationStoreScriptContent@5db3f5b4': 00180002 TypeError: Cannot read property "id" from null (/WEB-INF/webscripts/categories/categories.get.js#35)
org.springframework.extensions.webscripts.WebScriptException: 00180003 Failed to execute script 'org.springframework.extensions.webscripts.ResourceStore$WebApplicationStoreScriptContent@5db3f5b4': 00180002 TypeError: Cannot read property "id" from null (/WEB-INF/webscripts/categories/categories.get.js#35)

Can you explain me why the fourth line of output is "result=null" ?
And why "result1", "result2", "result3" is not displayed ?

Thanks
5 REPLIES 5

amandaluniz_z
Champ on-the-rise
Champ on-the-rise

zomurn
Champ in-the-making
Champ in-the-making
ok thanks.
Below, another test.

Input code :

for(var i = 0; i < categories.length; i++) {
      var result = connector.get("/deckshare/categoryChildren/path/"+categories[i]);
      if(result != null && result != "" && result != undefined) {
         logger.log("isEmptyTest :");
         logger.log(isEmpty(result));
         logger.log(result);
         logger.log(String(result));
         var obj = eval('(' + result + ')');
         //for(var j = 0; j < obj.children.length; j++) {
            if(childSelected(obj, nodeId)) {
               //obj.expanded = "true";
            }
         //}
         results.push(obj);
      }
   }

function isEmpty(obj) {
   if (typeof obj == 'undefined' || obj === null || obj === '') return true;
   if (typeof obj == 'number' && isNaN(obj)) return true;
   if (obj instanceof Date && isNaN(Number(obj))) return true;
   return false;
}


Output result (space are displayed with '_' (underscore) caracter) :

12:22:41,461 DEBUG [org.alfresco.repo.jscript.ScriptLogger]_isEmptyTest_:
12:22:41,464 DEBUG [org.alfresco.repo.jscript.ScriptLogger]_false
12:22:41,464 DEBUG [org.alfresco.repo.jscript.ScriptLogger]_
12:34:37,318 DEBUG [org.alfresco.repo.jscript.ScriptLogger]_null

Can someone tell me the value of the "result" variable then ?

Thanks

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
Seems to be a string with a space: " "

amandaluniz_z
Champ on-the-rise
Champ on-the-rise
Sorry not… it's not a space….

zomurn
Champ in-the-making
Champ in-the-making
Yes, this is NOT a space, this is nothing.
Check again, I just have edited the code (String(result)) output added.

I don't understand this code…
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.