13 Replies Latest reply on Feb 20, 2015 3:25 AM by anthony_inovelan

    Using Ad-hoc sub processes

    Brian Wallis Master

      I've been looking at ad-hoc sub processes and haven't quite managed to work out how they would be used. I've seen Kris's blog page and demo but that didn't really help me and I also examined the test cases in jbpm-examples (BPMN2-AdHocSubProcess.bpmn2) for JBPM 6.0.0.CR2.

       

      In Kris's blog he says one of the features is

      • ad-hoc sub-process where the user can select process fragments to execute

      but I don't see how the user is meant to select a process fragment to execute without me (the developer) writing some sort of UI to enable this selection and send the signal to the session or adding some complexity to the workflow by including a human task to do something similar from a task with scripting.

       

      Am I missing something here? It seems to me that the support for the user selecting a process fragment in an ad-hoc sub process is missing (by support I don't necessarily mean a UI, more something missing from the task management API).

       

      thanks.

        • 1. Re: Using Ad-hoc sub processes
          Brian Wallis Master

          I have an example in mind for a use of an adhoc subprocess. This comes from a workflow we currently have that includes the ability to add a new text comment to a variable in the workflow. This note adding ability is included into every human task form through the workflow.

          This seems to be a case for using an adhoc workflow instead of this duplication in all the human task nodes.

           

          Something like this (the real flow is more complex)

          adhocNote.jpg

          The completion condition would be the completion of Book Appointment.

          The Enter Patient Details path would be started on entry to the subprocess.

          The AddNote task would need to be able to be started on user command at any time the sub process is active and also multiple times (or never).

           

          Does this sound like a valid use for an adhoc subprocess?

           

          I'm still not sure how this sits with the task interface which is I think is the only place the UI should be interacting with the workflow engine. How do I cause the AddNote task to run each time a user wants it to?

          • 2. Re: Re: Using Ad-hoc sub processes
            Brian Wallis Master

            I now have the above adhoc workflow working within my larger workflow  but I have had to add some extra code into my ProcessEventListener to activate the flows in the sub process.

             

                @Override
                public void afterNodeTriggered(ProcessNodeTriggeredEvent event)
                {
                    ProcessInstance process = event.getProcessInstance();
                    NodeInstance instance = event.getNodeInstance();
                    Node node = instance.getNode();
                    String nodeType = node.getClass().getSimpleName();
            
                    logger.info("AfterNodeTriggered event, id = " + process.getId() + " node name = " + instance.getNodeName()
                            + " node type = " + nodeType);
                    if(node instanceof DynamicNode)
                    {
                        DynamicNode adhocNode = (DynamicNode)node;
                        for(Node n : adhocNode.getNodes())
                        {
                            if(n.getIncomingConnections().size() == 0)
                            {
                                // One of the adhoc process flows?
                                logger.info("Starting node of an adhoc flow: name = "+n.getName() + " type = "+n.getClass().getSimpleName());
                                process.signalEvent(n.getName(), null);
                            }
                        }
                    }
                }
            

             

            I worked out what to add by a bit of trial and error. I couldn't find out how to query a node for its type, its class seems to be DynamicNode so I used that. I then iterate through all the nodes and send signals to the ones that don't have any incoming connections. This activates each of the flows in the adhoc subprocess which let me experiment with the workings of an adhoc process. It only activates them once on subprocess entry which is not quite what I want

             

            A few questions/issues:

            1. I really want the user to be able to select which adhoc flow they want to activate but there doesn't seem to be any support for this. Do I need to write my own "available flows" management and UI support for this? I realise this is not strictly a part of human task management but it seems like it should be possible for a user to get a list of the flows that are available in an adhoc subprocess and to select one and activate it. This is really going to look like just another task to the user.
            2. I noticed that the on-entry and on-exit scripts don't seem to get executed for the adhoc subprocess.
            3. I used a completion condition copied from one of the unit tests, getActivityInstanceAttribute("numberOfActiveInstances") == 0. I can guess what this does but I couldn't find any other documentation on this or other functions that might be available for this.
            4. The designer in eclipse doesn't like the adhoc sub process and flags every node that doesn't have an incoming connection as an error. I don't think it is an error for the adhoc sub process and the process does deploy and run ok. Is this a bug in the designer?

             

            I'm still trying to work out how I would use an adhoc sub process in conjunction with users and the tasks they want to perform.

             

            Any comments would be welcome.

             

            thanks

            • 3. Re: Using Ad-hoc sub processes
              Brian Wallis Master

              To continue my one sided conversation ...

               

              I now have an adhoc sub process working just about how I wanted it.

               

              I wanted one human task that can be run as many times as the user wants to (AddNote) and a second flow with three tasks that the user can run once and when that flow completes then the adhoc sub process should exit. It is not yet quite implemented as I would like I want but it is useable. (it seems a bit clumsy).

               

              I have a bit of code in a ProcessEventListener that kicks things off similar to the code above, now I just look in the DynamicNode (the adhoc sub process) for a human task node with a particular name, "Select Activity", and signal it to start. This would be better if done in the adhoc node entry script rather than relying on an event listener but the entry (and exit) scripts don't seem to be invoked when the node is entered/exited.

               

              The ability to start any other human task node in the adhoc sub process is now implemented by the flow starting with the "Select Activity" node. This just presents a form with a drop down with an entry for each other start node (AddNote and Enter Patient Details) and the following script node just sends a signal to the selected node to launch it.

               

              Another issue is that the completion condition for the adhoc node doesn't seem to work so I've used an error signal at the end of the Enter Patient Details flow.

               

              The final flow looks like this...

              adhocnode.jpg

              • 4. Re: Using Ad-hoc sub processes
                John Vogel Newbie

                Brian, thank you for posting this information, it's very helpful. I'm working on using jBPM for adaptive case management and, from the documentation, it's not clear how to do that. This is the best insight I've seen yet.

                 

                John

                • 5. Re: Using Ad-hoc sub processes
                  Oleg Efimov Newbie

                  It seems that jBPM community is a little dead -- almost every question across the Internet on jBPM is left unanswered...

                  • 6. Re: Using Ad-hoc sub processes
                    Mauricio Salatino Master

                    Don't be so negative, this thread has 4 answers and most of the time people doesn't mind marking the whole question as answered when they get what they want.

                    You will find my messages asking for people to close the questions, but to be honest 20% of the time that happens. As soon as they get the answer they just go away, so don't relay on Answered vs Unanswered questions to measure the community state.

                    • 7. Re: Using Ad-hoc sub processes
                      Oleg Efimov Newbie

                      Mauricio, 3 of the 4 answers are from the author of the question, and the 4th is kind of 'thanks'. There are no answers from product developers, gurus etc.

                       

                      I didn't mean to be offending, sorry if I did.

                      • 8. Re: Using Ad-hoc sub processes
                        Mauricio Salatino Master

                        Oleg, this is a complex question and in order to answer it you need some time. The main idea of a community is that users needs to interact and share thoughts about different issues. You cannot rely on the developers that needs to spend time improving the framework to be answering all the 100 questions that are posted in here and in stack overflow for example.

                        I've noticed that you have just join, so instead of complaining you can start a discussion with Brian (who started this thread) about the topic of this thread.  I believe that it will be more useful than complaining.

                        • 9. Re: Using Ad-hoc sub processes
                          Oleg Efimov Newbie

                          Mauricio, thank you for your interesting opinion on how communities work I have no idea how to help Brian -- actually I have the same question (that's how I got to this thread).

                           

                          And speaking of helpfulness -- maybe you would write something on the subject of this thread? I found no clues as how to initiate ad-hoc subprocess tasks from the UI of Business Central.

                           

                          At least reply "there is no functionality at the moment, you have to develop your own UI" would help.

                          • 10. Re: Using Ad-hoc sub processes
                            anthony_inovelan Newbie

                            Well, I may be a little off the topic but I have some questions about "using ad-hoc sub process" :

                            - I'm using jBPM 6.1.0.Final, and creating a process with Drools Workbench

                            - I have a "main process" which contains an adhoc sub-process with some simple User Tasks inside

                            - I start my main process, and I start / complete some tasks

                            - Then arrives the "adhoc sub process" node in my process flow, my process is now waiting for some action in order to continue the flow after the "adhoc sub process" node, it's waiting for the sub-process node to complete.

                            - And here come the questions : (related to each other)

                                 . how can I complete my adhoc sub-process node ?

                                 . what can I put in the property AdHocCompletionCondition ? (I've seen a few things about "getActivityInstanceAttribute" online...)

                                 . how can I start and complete User Tasks of the adhoc sub-process ? (access to the tasks ids ?)

                             

                            Thanks !

                            • 11. Re: Using Ad-hoc sub processes
                              anthony_inovelan Newbie

                              Here is my process :

                              process3.png

                               

                              I'm still trying to figure it out :

                              - I've found some "example" here : jbpm/ProcessTest.java at master · droolsjbpm/jbpm · GitHub and I don't really understand what this line does :

                              // signaling to select tasks in the ad-hoc sub-process

                              ksession.signalEvent("Investigate", null, processInstance.getId());

                               

                              Thanks again !

                              • 12. Re: Using Ad-hoc sub processes
                                anthony_inovelan Newbie

                                Okay, so if I want to activate the task "form 2" of my subprocess (in order to complete this task afterwards), this line will work : "ksession.signalEvent("form 2", null, processInstance.getId());"


                                But why do we have to use the "visual name" of the node ? instead of the "task name" ?

                                What's the difference between "Name" and "Task name" in the properties of a User Task ? (see below : French version)

                                names.PNG


                                Now I just have to figure out the completion condition, but it seems incomplete for now : [JBPM-4176] ad-hoc sub process completion conditions not implemented - JBoss Issue Tracker

                                • 13. Re: Re: Using Ad-hoc sub processes
                                  anthony_inovelan Newbie

                                  I've put this code "getActivityInstanceAttribute("numberOfActiveInstances") == 0" in the completion condition and it works when I activate (and complete) one of the nodes inside the sub-process, the "sub-process node" is completed and my main process ends.

                                   

                                  Is it possible to skip the ad-hoc sub process ? (without completing any of its nodes)