Workflow – parameters / variables – taskid – processid

In the process definition (in the <node-enter> ) part, i want to get the taskId.


var taskId = “jbpm$” + executionContext.getProcessInstance().getTaskMgmtInstance().getId();


Picking up new stuff rather quickly now.

It seems I start to understand Alfresco. I can make custom actions, nice action buttons, run Javascripts (inside & outside alfresco) without errors. I can adress spaces & nodes and access their parameters now.

So level up !!!

We now need to find nodes & space within the repository without looking for names. So I created aspect like

– isCollection
– isHidden
– isConfigFile

Based on a location X where I start my script (see previous post how to get that location and context in a Javasscript) I want to find a Space somewhere higher up the tree. And where “before” i searched for a name of a space, i now search for an .hasAspect(“namespace_x:isHidden”) and if that’s true I do my stuff.


in ContentModel.xml adding aspects like this:

<aspect name=”mjb:isPlanning”>
<property name=”mjb:isPlanning”>
<title>MJB Planning</title>
<association name=”mjb:isPlannable”>
<title>Planning Space</title>

how to adres the behaviour variable in a alfresco javascript

I`m making some “On-Create-Folder” behaviour.

– To make things simple i created a “behaviour action” button (aka a custom action) which calls a javascript which I stored in the datadictionairy / scripts folder. This script is stored inside the Alfresco repository. It’s called aaa_onCreateNode.js and  does only this :

logger.log(” GOTCHA from ALFRESCO repository”);

This script is triggered manually by pressing the button.

– I have another script which is located outside the repository & stored on this location: alfresco/extension/scripts/behaviours/aaa_onCreateNode.js
This is running from the classpath

<bean id=”onCreateNode” class=”org.alfresco.repo.policy.registration.ClassPolicyRegistration” parent=”policyRegistration”>
<property name=”policyName”>
<property name=”className”>
<property name=”behaviour”>
<bean class=”org.alfresco.repo.jscript.ScriptBehaviour” parent=”scriptBehaviour”>
<property name=”location”>
<bean class=”org.alfresco.repo.jscript.ClasspathScriptLocation”>

This script is called automatically when I create a new space.

So now I have both scripts up & running, I need to access some environment parameters. I want to know for example from which location I am working from.

The parameter behaviour works for the script which is automatically started (aka the script run from the classpath) So this gives me all the handles I need to do stuff.

if ( != null && == “onCreateNode”){
var childAssoc = behaviour.args[0];
var node = childAssoc.getChild();
var companyhome = search.findNode(“path”, [‘workspace’,’SpacesStore’,’app:company_home’]);




Starting with an empty SQL database.

I did this before. Actually many times before actually, but if I don’t practice enough or document how to do it, I forget how to do it. I am (of course) talk about dropping and recreating a database.

So here’s how to drop the local alfresco SQL database and create a new *fresh* one.

– Start command windows (Str => Run => CMD)
–  cd C:\alfresco-enterprise-tomcat-3.4.4\mysql\bin

(make sure the database is running at this time)

mysql -ualfresco -palfresco

mysql> drop database alfresco;
mysql> create database alfresco default character set utf8 collate utf8_bin;

I renamed the folder : C:\alfresco-enterprise-tomcat-3.4.4\alf_data\
to C:\alfresco-enterprise-tomcat-3.4.4\alf_data_old
and copied the underlying folders mysql and oouser back to the new alf_data folder.

Then restart Alfresco & it should be working.
All empty, all fresh.
Time to put in some new stuff.

NodeService vs nodeService

No, i am not speaking about a class and the instance of that class.

There are 2 node service beans “nodeService” and “NodeService”. The first is the internal bean, the second is the public service: the first bean wrapped with security and transactional proxies.

For a day I have been searching how to solve the error:

No authentication provider for net.sf.acegisecurity.providers.UsernamePasswordAuthenticationToken

My Java class defined this:
NodeService nodeService = serviceRegistry.getNodeService();
Now I found out that this is the one with more security settings.

To solve it, I added the bean property:

<property name=”nodeService”>
<ref bean=”nodeService” />

And added this function to my .java class

public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;

Big thanks to this post :

And so now it’s working. Time to get to cracking at the interesting part…

Workflows through JavaScript

This has a good description of the methods available in Alfresco to do stuff with the workflows;

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