Search code examples
jsonalfrescoactivitibpmnjsonparser

Parse JSON string inside activiti bpmn


Greetings to the community! I am using Alfresco 6.0.0 Community edition with the embedded Activiti engine. I am creating many kind of different processes/tasks through .bpmn files and now I would like to somehow achieve the following scenario:

1) Deploy a .bpmn file with 2 usertasks (usertask1 -> seqflow -> usertask2).

2) While being on the first task I set/update a process variable and set to it a JSON formatted String (f.e "{ id: '100', name:'X'}" )

My question is if there is any possible way to parse that JSON (f.e to obtain the 'id' or the 'name' values ) inside the bpmn?? I want to achieve this inside the usertask2, is there any possible way? Maybe something in the ScriptTaskListener or any other listener?? Any help would be greatly appreciated.

Thanks :)

Here is the usertask

 <userTask id="task2" name="${nameSetOnTask1}"
        activiti:formKey="wf:adhocTask">
       <documentation> Second task </documentation>
       <extensionElements>
           <activiti:taskListener event="create" class="org.alfresco.repo.workflow.activiti.tasklistener.ScriptTaskListener">
              <activiti:field name="script">
                 <activiti:string>
                  var json = execution.getVariable('json') <!-- this is the string with json value -->

                 </activiti:string>
              </activiti:field>
           </activiti:taskListener>
       </extensionElements>
    </userTask>

Solution

  • SOLVED

    I managed to parse the Json String using the Javascript's JSON.parse function

    <activiti:string>
       var json = execution.getVariable('json')
       var jsonObject= JSON.parse(json) ;
       var idValue = jsonObject.id                        
    </activiti:string>