cancel
Showing results for 
Search instead for 
Did you mean: 

Pass result from javascipt to ftl template

robertoroberto
Champ in-the-making
Champ in-the-making
Hi, I have a webscript that add categories to the classification tree:

———– addCategoryPathtoPath.js ———

function addCategoryPath2Path(newpath,pth)
{
    
  var nodes_x_level = decodeURI(pth).split(".");
  var node = null;


var rootTgt = null, nodeIndex = null;
var rootNodes = classification.getRootCategories("cm:generalclassifiable");
var found = false; var styleFound="";

for(node in nodes_x_level)
{  found = false;
for(nodeIndex in rootNodes)

    rootTgt = null;   
if (rootNodes[nodeIndex].properties.name==nodes_x_level[node])
       { rootTgt = rootNodes[nodeIndex];
         out+="matching…"+rootTgt.properties.name+" == "+nodes_x_level[node]+"<br>";
        break; }
  }
   if  (rootTgt!=null)
  {   rootNodes = rootTgt.immediateSubCategories;  
      found=true;
   } else { out+="No matching for node:"+nodes_x_level[node]+" (abort) <br> <br>"; break; }


}



   if  (found==true) 
{
var idx = 0;
var  tmpCatNode = null;
var addedcategories = decodeURI(newpath).split(".");

for (idx in addedcategories)
{   tmpCatNode = rootTgt.createSubCategory(addedcategories[idx]);   
    rootTgt =tmpCatNode;
}

  styleFound ="<font color=green>Sub-Categories Path : <br> <em>"+newpath+"</em>  was created! </font>"; 

}
  else 
{  styleFound="<font color=red>Creation Failed!</font>";  }

   return (out+styleFound);
}


function doIt(){
   var name = args["subpath"]; var path = args["path"];
   res =  addCategoryPath2Path(name,path);
   return res;
}

model.res=doIt();


—— addCategoryPathtoPath.get.html.ftl ————

<html>
   <head>
   </head>
   <body>
      ${res}
      
   </body>
</html>

I have this error; Can you help me? How can I pass result(res) from javascript to ftl response file?

500 Description: An error inside the HTTP server which prevented it from fulfilling the request. 
  
Message: Error during processing of the template 'Expression res is undefined on line 6, column 19 in org/alfresco/office/addCategoryPathtoPath.get.html.ftl.'. Please contact your system administrator. 
  
Exception: freemarker.core.InvalidReferenceException - Expression res is undefined on line 6, column 19 in org/alfresco/office/addCategoryPathtoPath.get.html.ftl. 


regards
2 REPLIES 2

davidc
Star Contributor
Star Contributor
By using the model root object as you've done.

Perhaps your doit() method is returning a null value.

mark_smithson
Champ in-the-making
Champ in-the-making
Shouldn't the js be name addCategoryPathtoPath.get.js ?

As it is at the moment it would not be executed for a get request.

Also I can't see the out variable in the js being declared anywhere (perhaps I am missing it)?