cancel
Showing results for 
Search instead for 
Did you mean: 

Can't list workflows

sgartner
Champ on-the-rise
Champ on-the-rise
Hi All and thanks in advance for your help,

I am running Alfresco Community Edition 3.2, and I am trying to write a web script to list all workflows.  I thought it would look like the script below, but workflow.latestDefinitions throws an exception:

Expression workflow.latestDefinitions is undefined on line 14, column 10 in test/listWorkflows.get.html.ftl

I've also tried using workflow.allDefinitions but it also throws undefined.

Here's what I see in the Workflow Console, so this is what I expected to be returned by latestDefinitions:

id: jbpm$4 , name: jbpm$wcmwf:changerequest , title: Change Request , version: 1
id: jbpm$2 , name: jbpm$wf:adhoc , title: Adhoc Task , version: 1
id: jbpm$6 , name: jbpm$inwf:invitation-nominated , title: Invitation - Nominated , version: 1
id: jbpm$1 , name: jbpm$wf:review , title: Review & Approve , version: 1
id: jbpm$7 , name: jbpm$imwf:invitation-moderated , title: Invitation - Moderated , version: 1
id: jbpm$3 , name: jbpm$wcmwf:submit , title: Web Site Submission , version: 1
id: jbpm$5 , name: jbpm$wcmwf:submitdirect , title: Web Site Submission (Direct) , version: 1

Here is listWorkflows.get.html.ftl:

All active workflows:
<table cellspacing=0 cellpadding=2>
  <tr>
    <th>ID</th>
    <th>Name</th>
    <th>Description</th>
    <th>Title</th>
    <th>Version</th>
    <th># active</th>
  </tr>
  <tr>
    <td colspan="6"><hr/></td>
  </tr>
  <#list workflow.latestDefinitions as def>
    <tr>
      <td>${def.id}</td>
      <td>${def.description}</td>
      <td>${def.name}</td>
      <td>${def.title}</td>
      <td>${def.version}</td>
      <td>${def.activeInstances}</td>
    </tr>
  </#list>
</table>

What did I do wrong?
2 REPLIES 2

tfrith
Champ on-the-rise
Champ on-the-rise
Take a look at http://wiki.alfresco.com/wiki/Workflow_JavaScript_API

try workflow.getLatestDefinitions().

You are close but just trying to use latestDefinitions as a property of the workflow object (workflow.latestDefinitions) rather than as a function of it (workflow.getLatestDefinitions() ).

Here I am talking about the JavaScript API and not the Freemarker (template API).
Look at http://wiki.alfresco.com/wiki/Template_Guide#Workflow for Freemarker.  You don't get the same functions - in particular you can't see the definitions, just the tasks.

You could just do the work in the .js file of the web script.  Make the call above, then put the results into json or some form that can be displayed on the client side.  Maybe just a simple string that includes the <td> tags. then just output that in Freemarker.

sgartner
Champ on-the-rise
Champ on-the-rise
Take a look at http://wiki.alfresco.com/wiki/Workflow_JavaScript_API

try workflow.getLatestDefinitions().

You are close but just trying to use latestDefinitions as a property of the workflow object (workflow.latestDefinitions) rather than as a function of it (workflow.getLatestDefinitions() ).

Here I am talking about the JavaScript API and not the Freemarker (template API).
Look at http://wiki.alfresco.com/wiki/Template_Guide#Workflow for Freemarker.  You don't get the same functions - in particular you can't see the definitions, just the tasks.

You could just do the work in the .js file of the web script.  Make the call above, then put the results into json or some form that can be displayed on the client side.  Maybe just a simple string that includes the <td> tags. then just output that in Freemarker.

Thanks for the response!  The documentation is a bit confusing and the WIKI doesn't even currently contain a reference to latestDefinitions.  So, I looked in the newest API reference and though the API documentation does use the phrase "Returns an array" the API clearly lists latestDefinitions  as a property.  However, to leave no stone unturned, I tried what you suggested and it didn't work.  But it did lead me to a solution.  So, while I still don't know why the original FTL doesn't work properly (it seems like it should have), this did:


var outputRows = "";
for each (var def in workflow.latestDefinitions)
  {
    outputRows += "<tr>";
    outputRows += "  <td>" + def.id              + "</td>";
    outputRows += "  <td>" + def.description     + "</td>";
    outputRows += "  <td>" + def.name            + "</td>";
    outputRows += "  <td>" + def.title           + "</td>";
    outputRows += "  <td>" + def.version         + "</td>";
    outputRows += "  <td>" + def.activeInstances + "</td>";
    outputRows += "</tr>"
  }

model.outputRows = outputRows;

Then I changed the FTL to this:

All active workflows:
<table cellspacing=0 cellpadding=2>
  <tr>
    <th>ID</th>
    <th>Name</th>
    <th>Description</th>
    <th>Title</th>
    <th>Version</th>
    <th># active</th>
  </tr>
  <tr>
    <td colspan="6"><hr/></td>
  </tr>
  ${outputRows}
</table>

This works, and I am clearly using workflow.latestDefinitions as a property, not a function call.

Note that it certainly seems to me that this should have worked as well, but doesn't:
model.workflowLatestDefinitions = workflow.latestDefinitions;


  <#list workflowLatestDefinitions as def>
    <tr>
      <td>${def.id}</td>
      <td>${def.description}</td>
      <td>${def.name}</td>
      <td>${def.title}</td>
      <td>${def.version}</td>
      <td>${def.activeInstances}</td>
    </tr>
  </#list>

I suspect this is another example of the error where Alfresco simply doesn't pass some objects from JavaScript to FreeMarker properly (see http://forums.alfresco.com/en/viewtopic.php?f=36&t=25847).