I am having big problems to get my webscript working. Best thing is that ín the Alfresco JavaScript Console everything is working. Not if I deploy the webscript.
javascript:
try {
var nodeRefs = args[0].split('&');
var paths = [];
for (var n in nodeRefs) {
var doc = search.findNode(nodeRefs[n]);
var path = doc.displayPath + "/" + doc.name;
var host = headers['Host'];
path = path.replace('/Firmen-Home/Sites', '');
path = path.replace('/Companyhome/Sites', '');
path = path.replace(/\//g, '\\');
paths.push("\\\\" + host + "@7070\\alfresco" + path);
}
model.paths = paths;
model.nodeRefs = nodeRefs;
} catch (e) {
}
freemarker template:
<#escape x as jsonUtils.encodeJSONString(x)>
<#assign nodeRefs = nodeRefs>
{
<#assign n = 0>
<#list paths as path>
"${nodeRefs[n]}" : "${path}"<#if path_has_next>,</#if>
<#assign n = n + 1>
</#list>
}
</#escape>
JavaScript Console Output (I used the same noderef 3 times for testing):
{
"workspace:\/\/SpacesStore\/5fa74ad3-9b5b-461b-9df5-de407f1f4fe7" : "\\\\localhost:8080@7070\\alfresco\\swsdp\\documentLibrary\\Budget Files\\budget.xls",
"workspace:\/\/SpacesStore\/5fa74ad3-9b5b-461b-9df5-de407f1f4fe7" : "\\\\localhost:8080@7070\\alfresco\\swsdp\\documentLibrary\\Budget Files\\budget.xls",
"workspace:\/\/SpacesStore\/5fa74ad3-9b5b-461b-9df5-de407f1f4fe7" : "\\\\localhost:8080@7070\\alfresco\\swsdp\\documentLibrary\\Budget Files\\budget.xls"
}
I get 3 different Errors from the deployed webscripts at all possible solutions I tried:
freemarker.core.ParseException - Encountered "{" at line 1, column 19 in convert/uuidsToPaths.get.json.ftl. Was expecting one of: "in" ... ">"
freemarker.core.InvalidReferenceException: Error on line 3, column 9 in convert\uuidsToPaths.get.json.ftl nodeRefs is undefined. It cannot be assigned to nodeRefs
Expected collection or sequence. paths evaluated instead to freemarker.template.SimpleHash
What am I mussing here? I tried ${nodeRefs}, $nodeRefs, {nodeRefs} .... but nothing seems to work.
Regards, Michael
EDIT:
JavaScript Controler:
function main() {
var nodeRefs = args[0].split("_");
var paths = [ nodeRefs.length ];
var i = 0;
for ( var n in nodeRefs) {
var doc = search.findNode(nodeRefs[n]);
var path = doc.displayPath + "/" + doc.name;
var host = headers["Host"];
paths[i] = "\\" + host + "@7070\alfresco\\" + path;
i++;
}
model.code = "200";
model.paths = paths;
model.nodeRefs = nodeRefs;
}
main();
Freemarker JSON
<#escape x as jsonUtils.encodeJSONString(x)>
{
"status" : {
"code" : ${code} // easier to differ success from error
},
<#assign n = 0>
<#list paths as path>
"${nodeRefs[n]}" : "${path}"<#if path_has_next>,</#if>
<#assign n = n + 1>
</#list>
}
</#escape>
${someExpression}, the other two is just static text and will be printed as is. - ddekany#assignfor nodeRefs since you already got the array stored in yourmodel.nodeRefs? Also: the error seems to be pointing out yourpathssequence is not a proper array but a simplehash. It could be that your array is stored with keys and values instead of solo values like:paths[0].value = \\\\localhostandpath[0].key = 8080@7070\\alfresco\\swsdp\\documentLibrary\\Budget Files\\budget.xls. Try to check that. Btw, the correct syntax for index seq is:${seq[n]}- TeqnologynodeRefsis just an array which stores an unknown amount of noderefs). @Alch3mi5t how else can I dynamically creat and extend an array where the size of it can differ for each call? - Pali<#assign nodeRefs = ${nodeRefs}>throwsfreemarker.core.ParseException: Encountered "{" at line 2, column 19- Pali