Workflows through JavaScript

This has a good description of the methods available in Alfresco to do stuff with the workflows; http://wiki.alfresco.com/wiki/Workflow_JavaScript_API

To make this work;
– create a Javascript file in the data dictionairy and enter the code below.
– Make sure there is a workflow available.
+ check : http://localhost:8080/alfresco/faces/jsp/admin/workflow-console.jsp
+ Enter show definitions all
  + fill in the name in the first line.
– It needs also an active workflow to get stuff like InstanceID.

var naam_wf = “wf:ADHOC”;            // name of the processdefinition of the workflow
var workflowType = “jbpm$” + naam_wf;

var wf_all_definition = workflow.getAllDefinitions();
logger.log(“REPORT – ALL_DEFINITIONS =”+ wf_all_definition);
var wf_definition = workflow.getDefinitionByName(workflowType);
logger.log(“REPORT – DEFINITION =”+ wf_definition);
var wf_description = wf_definition.getDescription();
logger.log(“REPORT – DESCRIPTION =”+ wf_description);
var wf_definition_id = wf_definition.getId();
logger.log(“REPORT – (ADHOC) ID =”+ wf_definition_id);
var wf_instances = wf_definition.getActiveInstances();
logger.log(“REPORT – INSTANCE =”+ wf_instances);
var wf_instance_id = wf_instances[0].getId();
logger.log(“REPORT – INSTANCE_ID =”+ wf_instance_id);
var wf_instance_paths = wf_instances[0].getPaths();
logger.log(“REPORT – PATHS =”+ wf_instance_paths);
var wf_tasks = wf_instance_paths[0].getTasks();
logger.log(“REPORT – TASKS =”+ wf_tasks);
var wf_tasks_length = wf_tasks.length;
logger.log(“REPORT – NUMBER OF TASKS = “+ wf_tasks_length);
var wf_task_name = wf_tasks[0].getDescription();
logger.log(“REPORT – TASK[0] – DESCRIPTION =”+ wf_task_name);

 

Custom Model

Since I always forget ;

I update this one : …./config/extension/model/customModel.xml
The …./config/extension/custom-model-context.xml is still the same (contains a bean referring to the above file)

I have to update the web-client-config-custom.xml and add
– my newly defined types to the list of the Content Wizards
– my newly defined aspects to the list of the Action Wizards
– then define all types here with their properties showing
– then define all aspects with their properties and associations showing

And this is enough to update the custom model

(no) logging in workflow

I’m trying to achieve logging from javascript code in a workflow, but with no success.
This is an excerpt from the workflow code I’m using:

<event type=”process-start”>
<action>
<script>
logger.log(“Message X”);
</script>
</action>
</event>

C:\alfresco-enterprise-tomcat-3.4.4\tomcat\webapps\alfresco\WEB-INF\classes\log4j.properties
contains:
      log4j.logger.org.alfresco.repo.workflow=DEBUG 

That should be good, but no logging information.

https://forums.alfresco.com/en/viewtopic.php?f=10&t=21838 gave me the answer.

# Repository
….
log4j.logger.org.alfresco.repo.jscript=error
log4j.logger.org.alfresco.repo.jscript.ScriptLogger=debug    <= set this one .
log4j.logger.org.alfresco.rep…..

And also –

My script needs to be encapsulated by the action class AlfrescoJavaScript.

<action class=”org.alfresco.repo.workflow.jbpm.AlfrescoJavaScript”>
<script>
logger.log(“Ad Hoc Task”);
</script>
</action>

Workflow console

The link to my personal workflow console ; http://localhost:8080/alfresco/faces/jsp/admin/workflow-console.jsp

I`m testing all kinds of variations of workflows. (simple workflow, but mostly variations of the advanced workflow) Because trial and error clutters up my Alfresco environment, I want to clean up all the old (non-working) workflows.

If I understood correctly Alfresco does not delete the older workflows. If a workflow crashed (due to any number of reasons – aka wrong names, unreachable variables, wrongly defined names etc.) the workflow step is kept alive in the system. This is great for produktion systems, but for testing it’s not that convenient.

So i`ll delete them through the management console.

show definitions all     – show me all workflows that still exist in the system

delete all workflows imeanit   –  my personal favorite, but a ruthless one..

undeploy definition name jbpm$incentroWorkflow – remove this workflow from the system.

undeploy definition jbpm$26  – remove workflow with this number

Using the Adhoc workflow model

I’ve created the adhoc model from the wiki example; http://wiki.alfresco.com/wiki/WorkflowAdministration

I created 3 files and it’s working (hooray)

C:\alfresco-enterprise-tomcat-3.4.4\tomcat\shared\classes\alfresco\extension\custom-workflow-context.xml

C:\alfresco-enterprise-tomcat-3.4.4\tomcat\shared\classes\alfresco\extension\workflow\adhoc\adhocModel.xml

C:\alfresco-enterprise-tomcat-3.4.4\tomcat\shared\classes\alfresco\extension\workflow\adhoc\processdefinition.xml

– the content of the files can be found at the above named wiki page

Now I want to place the functions in my own name space (incentro of course) and this seems to be an issue. It’s not working.. I haven’t figured out why yet. Just renaming the wf:prefix with an incentro:prefix did not work. There must be something I am missing….

More workflows in Alfresco

Still working on workflows;

This is  good example to make a workflow with a lifecycle.

http://wiki.alfresco.com/wiki/WorkflowSample_Lifecycle

I only run into some issues with user authentication. If I start a workflow (as admin) on a txt document and refer it to a user (myself) there are some authentication errors. It might have something to do with this code;

<swimlane name=”reviewer”>
<assignment class=”org.alfresco.repo.workflow.jbpm.AlfrescoAssignment”>
<actor>#{bpm_assignee}</actor>
</assignment>
</swimlane>

I have no solution yet.. So back to research..

Workflows

I am following the http://wiki.alfresco.com/wiki/WorkflowAdministration step-by-step guide to creating a custom workflow.

The anwser to my question, regarding how to get / where to place a new custom-workflow-context.xml file got answered in this very usefull forum topic –  https://forums.alfresco.com/en/viewtopic.php?f=30&t=35459

I am once again a little frustrated with the Alfresco system.
Why? The “hello world” workflow won’t work… The simplest.xml workflow didn’t work.
And “A system error happened during the operation: null”  is not really a good error in my humble opinion.

Diagonal Alfresco

It feels like i`m going through Alfresco diagonally. What I mean by that is that I figure out how something works (the proof of the pudding), then park my solution, and continue to figure out something else.

This is mainly because of the project we’re working on now. We proposed an Alfresco solution to a customer where we try to stay really close to default Alfresco behaviour.
Now we are figuring out how to solve things as nicely as possible, without having a content model yet to test everything on.

And so time to figure out something else today.

Custom Actions

I added two custom actions to my alfresco environment. This was (relatively) easy to do;

(1) Add the actions you want to  web-client-config-custom.xml

...
<actions>

<action id="CreateMessage">
<permissions> <permission allow="true">Write</permission> </permissions>
<label>CreateMessage</label>
<image>/images/icons/email_users_large.gif</image>
<script>/Company Home/Data Dictionary/Scripts/CreateMessage.js</script>
<params> <param name="nodeRef">#{actionContext.nodeRef}</param> </params>
</action>

<action id="SendMessages">
<permissions> <permission allow="true">Write</permission> </permissions>
<label>SendMessages</label>
<image>/images/icons/check_out_large.gif</image>
<script>/Company Home/Data Dictionary/Scripts/SendMessages.js</script>
<params> <param name="nodeRef">#{actionContext.nodeRef}</param> </params>
</action>	

<action-group id="space_details_actions">
<action idref="CreateMessage" />
<action idref="SendMessages" />
</action-group>

<action-group id="space_browse_menu">
<action idref="CreateMessage" />
<action idref="SendMessages" />
</action-group>

</actions>

(2) Update your scripts.

– Add this to the beginning of your script

nodeRef = args["nodeRef"];
var space = search.findNode(nodeRef);

– Add this to the end of your script

var goBack = "<script>history.back();</script>";
goBack;

That should be enough to make little icons in the details of a space, which will fire of the scripts named here.

Custom Behaviour

I`m trying to make my own custom behaviour in alfresco 3.4.4
This led me to a great example from the ECMArchitect – Jeff Potts.

Last week I got stuck on setting up & configuring his examples code.
I installed ANT and got that running, but Jeff’s example told me I had to configure the build.properties file.

(original version) 

alfresco.sdk.remote.home=/usr/local/bin/alfresco-sdk-2.1-enterprise/lib/remote
alfresco.sdk.server.home=/usr/local/bin/alfresco-sdk-2.1-enterprise/lib/server
alfresco.web.root=/usr/local/bin/apache/apache-tomcat-5.5.17/webapps/alfresco


After some searching I changed it into this : 

alfresco.sdk.remote.home=C:/alfresco-community-sdk-4.0.b/lib/remote
alfresco.sdk.server.home=C:/alfresco-community-sdk-4.0.b/lib/server
alfresco.web.root=C:/alfresco-enterprise-tomcat-3.4.4/tomcat/webapps/alfresco/

I didn’t have the SDK from alfresco installed, but now I downloaded it from the WIKI
( you should get this one: “Software Development Kit, including the source files” )

Unzipped to c: and referred the links to there. Then apparently we need to change windows backslashes (\\\\\\\\) into linux forwardslashes (////////)
Go figure….

So far so good, but I got some errors running ant in the C:\behavior-article\ folder.
This was solved by adjusting this line in the build.xml file :

(original)

<javac srcdir="${source.dir}" destdir="${bin.dir}" source="1.5" target="1.5" debug="on" fork="yes">
	<classpath refid="classpath"/>
</javac>

(my new version)

<javac srcdir="${source.dir}" destdir="${bin.dir}" source="1.5" target="1.5" includeantruntime="true" >
	<classpath refid="classpath"/>
</javac>

And so after adjusting this, it compiled correctly.
The ant deploy as described in jeff’s article worked in one go.
( as it should, but i was happy to see it working now)

And so now I get to play around the custom behaviour example….