8 Replies Latest reply on Aug 6, 2009 4:22 PM by Ronald van Kuijk

    taskform in the start activity - form vars dont get persiste

    Lalit Mathwani Newbie

      We are using JBPM v4 for a pilot at one of our institute labs.
      Since it's a pilot, we are not creating a separate UI to access the TaskService etc. We are instead leveraging the taskforms capability and using FTL templates for forms at different points in the workflow.

      One issue that we have run into is that if we have a form associated with the start activity, then none of the form params ( posted via HTTP when the workflow is started through the console) are being persisted into the JBPM4_VAR table till we introduce a halt in the workflow via a task associated with a user/group.

      Net effect of this seems to be that if you try to reference any of the form params before this task in the workflow, we get nulls.

      After the task (any task with a halt), the form params become available as process instance variables and can be used in the workflow..

      Is this an issue that others have run into? Or maybe we are doing something wrong?

      Here's the jpd.xml snippet..

      This works ..(note the halt we introduce via a manager_approval before we try to reference the hr_subcategory form variable in the is_lab_approval_needed decision activity).
      Trying to directly go from start to is_lab_approval_activity fails since hr_subcategory is resolved to null (we get a NPE).

      Also, one more quick question - we noticed that the JBPM4_HIST_VAR table never gets populated. The JBPM4_VAR table stores the process variables only as long as the process is active..If we dont want to create our own audit repo and leverage what JBPM4 provides out of the box, where do we see the process variables (we need some of these for an audit trail)?

      Regards,
      Lalit

      <?xml version="1.0" encoding="UTF-8"?>




      <event-listener class="gtri.jbpm.pilot.LogListener">

      </event-listener>





      <event-listener class="gtri.jbpm.pilot.LogListener">

      </event-listener>






      <event-listener class="gtri.jbpm.pilot.LogListener">

      </event-listener>




      <task candidate-users="peter,mary" form="gtri/jbpm/pilot/demo/manager_approval.ftl" g="163,10,131,40" name="manager_approval">

      <event-listener class="gtri.jbpm.pilot.LogListener">

      </event-listener>










      <event-listener class="gtri.jbpm.pilot.LogListener">

      </event-listener>


      <condition expr="#{(hr_subcategory=='newhire') || (hr_subcategory=='newconst') || (hr_subcategory=='badge') }"/>



        • 1. Re: taskform in the start activity - form vars dont get pers
          Lalit Mathwani Newbie

          looks like I didnt save the process snippet with the right escapes- sorry! Hope this does the trick :)

          <?xml version="1.0" encoding="UTF-8"?>
          
          <process name="GTRIHelpRequest" xmlns="http://jbpm.org/4.0/jpdl">
          
           <on event="start">
           <event-listener class="gtri.jbpm.pilot.LogListener">
           <field name="msg"><string value="starting the process GTRIHelpRequest"/></field>
           </event-listener>
           </on>
          
          
           <start form="gtri/jbpm/pilot/demo/request_help.ftl" g="0,0,80,40" name="start">
           <on event="start">
           <event-listener class="gtri.jbpm.pilot.LogListener">
           <field name="msg"><string value="In the start activity - start event - of GTRIHelpRequest process"/></field>
           </event-listener>
           </on>
           <transition to="debug_variables"/>
           </start>
          
           <script expr="Just dumping process variables" g="66,10,80,40" name="debug_variables" var="processVarABC">
           <on event="start">
           <event-listener class="gtri.jbpm.pilot.LogListener">
           <field name="msg"><string value="In the debug variables activity - start event - of GTRIHelpRequest process"/></field>
           </event-listener>
           </on>
           <transition to="manager_approval"/>
           </script>
          
           <task candidate-users="peter,mary" form="gtri/jbpm/pilot/demo/manager_approval.ftl" g="163,10,131,40" name="manager_approval">
           <on event="start">
           <event-listener class="gtri.jbpm.pilot.LogListener">
           <field name="msg"><string value="In the manager_approval_test activity - start event - of GTRIHelpRequest process"/></field>
           </event-listener>
           </on>
           <notification/>
           <transition g="-38,-18" name="Allowed" to="is_lab_approval_needed"/>
           <transition g="-38,-18" name="Sorry" to="request_rejected"/>
           </task>
          
          
          
           <decision g="354,85,80,40" name="is_lab_approval_needed">
           <on event="start">
           <event-listener class="gtri.jbpm.pilot.LogListener">
           <field name="msg"><string value="In the is_lab_approval activity - start event - of GTRIHelpRequest process"/></field>
           </event-listener>
           </on>
           <transition to="in_lab_approval_email">
           <condition expr="#{(hr_subcategory=='newhire') || (hr_subcategory=='newconst') || (hr_subcategory=='badge') }"/>
           </transition>
           <transition to="in_request_handling_email"/>
           </decision>
          


          • 2. Re: taskform in the start activity - form vars dont get pers
            Lalit Mathwani Newbie


            Looking through the JBPMv4 source, I get the impression that the 'Audit History for variables' feature is something that's not yet built in or supported. That *may* explain why the JBPM4_HIST_VAR table remains empty at all times. I think primarily that's because currently there is no 'variables' declaration section (yet) in jpdl-4.0.xsd , where we could declare whether a particular variable's history should be stored or not ..That seems to be goal for a future release (going by the code..see code snippets below)

            So, it does look like if you care about persisting the properties associated with the work units, you cant leverage the HIST_VAR table. If anyone has any other experience (other than creating your own audit table and persisting the variables there for audit trail purposes), I'd be really thankful if you could chime in ..

            Code snippets follow:
            I was hoping to find some place in the code where the JBPM4_HIST_VAR table will be updated.


            In org.jbpm.pvm.internal.model.ScopeInstanceImpl:

            for (VariableDefinitionImpl variableDefinition: variableDefinitions) {
             String key = variableDefinition.getName();
             Object value = variableDefinition.getInitValue(outerExecution);
             String typeName = variableDefinition.getTypeName();
             boolean isHistoryEnabled = variableDefinition.isHistoryEnabled();
             createVariable(key, value, typeName, isHistoryEnabled);
             }
            

            The createVariable call seems to be the one that will result through Hibernate into an insert into the JBPM4_HIST_VARs table.

            I looked through the code to find where the Variable definitions get initialized- it looks like JPdlParser in org.jbpm.jpdl.internal.xml does it in a method parseVariableDefinitions.

            That method looks for the following element definition in the jpdl file:
            for (Element inElement: XmlUtil.elements(element, "variable")) {

            But variable is not yet supported in jpdl-4.0.xsd. (the parseVariableDefinitions therefore is never called).

            Also if you look at the method itself, the isHistoryEnabled property of the variable is not even set when initializing the VariableDefinitionImpl..

             for (Element inElement: XmlUtil.elements(element, "variable")) {
             VariableDefinitionImpl variableDefinition = new VariableDefinitionImpl();
            
             String name = XmlUtil.attribute(inElement, "name", true, parse);
             variableDefinition.setName(name);
            
             int sources = 0;
            
             String initExpr = XmlUtil.attribute(inElement, "init");
             if (initExpr!=null) {
             variableDefinition.setInitExpression(initExpr);
             sources++;
             }
            
             Element valueElement = XmlUtil.element(inElement);
             if (valueElement!=null) {
             Descriptor initValueDescriptor = (Descriptor) WireParser.getInstance().parseElement(valueElement, parse);
             variableDefinition.setInitDescriptor(initValueDescriptor);
             sources++;
             }
            
             if (initRequired && sources==0) {
             parse.addProblem("no init specified", inElement);
             }
             if (sources>1) {
             parse.addProblem("init attribute and init element are mutually exclusive on element variable", inElement);
             }
            
             variableDefinitions.add(variableDefinition);
             }
            


            • 3. Re: taskform in the start activity - form vars dont get pers
              Ronald van Kuijk Master

              Have a look in the jira. Full support for task history is in there.

              Extensions/Patches/Fixes are always welcome.

              • 4. Re: taskform in the start activity - form vars dont get pers
                Joram Barrez Master

                Your other issue is interesting. Process variables from the start form should be available in the next activitites (altough they might not be persisted yet in the database, that's for performance reasons).

                Could you file a Jira issue precisly explaining your issue?

                • 5. Re: taskform in the start activity - form vars dont get pers
                  Setya Setya Newbie

                  I never knew that you can attach form in start node in jBPM4, what's the use case ?

                  Regards,

                  Setya

                  • 6. Re: taskform in the start activity - form vars dont get pers
                    Lalit Mathwani Newbie

                    Hi there,

                    Sorry, I should have checked the JIRAs first :)..would have saved me the code digging.

                    This one does seem to cover the future implementation of declarative task history auditing :
                    https://jira.jboss.org/jira/browse/JBPM-2416

                    I will open a JIRA on the other issue (start form params not being available till we have a task in the process).

                    The use case for us was that a user submits a help request form. On this form s/he makes some selections which drive decisions immediately on the form submission (eg is a lab approval needed etc).

                    You can associate forms with the start activity in JBPM4. We got the idea from the updated taskform sample here:
                    http://www.jorambarrez.be/blog/2009/07/21/jbpm-4-0-basic-taskform-tutorial-whats-new-part-4/
                    (thanks Joram - that was a great blog entry. Very clear explanations - Helped kickstart our pilot )

                    Regards,
                    Lalit

                    • 7. Re: taskform in the start activity - form vars dont get pers
                      Lalit Mathwani Newbie

                      JIRA for the issue relating to the start taskform params not being available without a halt :
                      https://jira.jboss.org/jira/browse/JBPM-2471

                      • 8. Re: taskform in the start activity - form vars dont get pers
                        Ronald van Kuijk Master

                         

                        "Setya" wrote:
                        I never knew that you can attach form in start node in jBPM4, what's the use case ?


                        In many cases the first step in the process is to fill out a form. But if this fails, you do not want a process instance to be started. So instead of starting one and then retrieving the form for the first task, you can now do it the other way around to.