Search code examples
jsonjbpm

JBPM FORM model using JSON as model


I am new to JBPM but we are creating user form human task which gets it data from an Angular app. The Angular Form is all dynamic and derived from an external database whichh holds the metadata for the Angular forms. We are using JBPM to hold the state so angular form data would Post to JBPM human task form with the data and complete the task. My question is I don't want to create a human form by adding all fields etc. Instead, I just want to send JSON string and somehow the Human task would be able to use that. Can I create a data object with a data column that will hold the JSON data? Also, would I be able to read the data from the task if I have to?


Solution

    1. Create a Data Object to declare the type of your object (inserted from the form)
    2. Declare a variable having as type your Data Object with the attributes as global variables (Variable Definitions of the process) [for example if you created a Data Object called Person having as attributes, id and name , you have to declare 3 global variables, one for the object person, and two variables for the id and name]
    3. Create a REST task (from service task), get your json response and assign its result to an object (declared in Variable Definitions)
    4. add a script task in which you assign to your global variables the values, example

      Person p = (Person) kcontext.getVariable("person"); //in the kcontext.getVariable() parameter you put the name of your global variable kcontext.setVariable("id",p.getId()); //id is the name of your global variable kcontext.setVariable("name",p.getName()); // name is your global variable as well

    5. go to the "Assignments" of your human task and add "Data Inputs and Assignments", now you give the name of your input data for the human task with their Data type, and you choose the Source of each input the global variable that you declared

    this should works, and I hope that this is what you are looking for, if you have a problem in implementing this, please type it in comments. good luck !