AnsweredAssumed Answered

Web Script response (json) in a presentation template (ftl)?

Question asked by pajel on Jan 4, 2011
Hello,
I am quite new here, so I am sorry if the answer is obvious, but I just haven't been able to find it anywhere so far…  :cry:

There is a beautiful web script out of the box in Alfresco 3.4.a which retrieves all completed workflow instances. It can be called by the following address and returns a json formatted response:

http://myserver:8080/alfresco/service/api/workflow-instances?state=Completed

The script works fine and, since I am missing the function to view all completed workflows in the Alfresco Explorer, I would like to expose the results of this script for the users inside the Alfresco Explorer. I got the idea that this might be done using a presentation template, thus I took the "general_example.ftl" from "Company Home > Data Dictionary > Presentation Templates" and started to editing it. After some googling and searching I ended up with the following code inside the "general_example.ftl" template:


<script>
function main()
{
  var connector = remote.connect("alfresco");
  var data = connector.get("/api/workflow-instances?state=Completed");
  var results = eval('(' + data + ')');
  model.complinstances = results["data"];
}
main();
</script>

<#list complinstances as complinstance>
    <p>${complinstance.id}</p>
</#list>

However, when displaying the "general_example.ftl" in Alfresco Explorer I get the following exception in Alfresco.log:

"Error during processing of the template 'Expression complinstances is undefined on line …, column … in workspace … "

I have even meddle with exposing the "remote" object to the JavaScript API according to this page http://drquyong.com/myblog/?p=49 but it just doesn't seem to work any more in version 3.4.a. Moreover, it seems to me like the script inside the ftl template doesn't even get executed…

Can anyone, please, find a mistake in my effort? Or am I going in a completely wrong direction?

Many thanks in advance for any help,
Pavel

Outcomes