添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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>

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>
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.