7 Replies Latest reply on Dec 17, 2015 5:05 AM by antonio peña

    How to know who has started a process?

    Andy McC Newbie

      What do I need to add to my process definition to access the Id of the user who has started the process?

       

      For example, if I'm logged in to jbm-console as "John" and start a new process, what mechanism do I have to find out that it was "John" who started the process. (The available examples seem to rely on the task form associated with the start event)

       

      There's quite an old post (How to know who has started a process ?), suggesting that I need to add a swimlane to the Start task (I assume this means the Start Event), but as this option isn't available via the designer, do I need to hand-edit some additional xml into the Start Event definition?

       

      Is there a better/official way?

       

      Thanks,

       

      Andy McC

        • 1. Re: How to know who has started a process?
          Mauricio Salatino Master

          We are already storing that information inside the jBPM Console NG logs. What we are doing is to use the currently logged user and store it in the process execution logs. Then you can query those logs in order to pick up the information about which user started a process. You can take a look at the ProcessInstanceLog class which already has the place to store the identity of the user that is starting the process:

           

          https://github.com/droolsjbpm/jbpm/blob/master/jbpm-bam/src/main/java/org/jbpm/process/audit/ProcessInstanceLog.java

           

          Depending on how you get the currently logged user in your application is how you will fill this attribute.

           

          Cheers

          1 of 1 people found this helpful
          • 2. Re: How to know who has started a process?
            Andy McC Newbie

            Thanks Mauricio - that's useful but my question probably wasn't clear enough.

             

            What I'm trying to do is access the currently logged-in user Id, without having to ask that user to enter it via a form every time they start a task. I was hoping I could add a script task to my process and from that use a method call of some kind (e.g .via kcontext) to access an Id field or similar. I guess that's what you're suggesting I could do using the ProcessInstanceLog link, but for various reasons I'm constrained to use the 5.4.0.Final tooling so I'm not sure I can exploit the Console NG developments.

             

            Where possible I'm trying to develop and deploy entirely from Drools-Guvnor and jbpm-console.

             

            It may be that I fall into a particular class of jBPM user who is more heavily biased to the BPMN-side of things and I'll confess that I don't have a background in enterprise apps, so I'm climbing several steep learning curves every day! I'm heavily reliant on Drools-Guvnor for building and deployment my stuff with some modest Java API calls contained within Script tasks.

             

            I can imagine that other users in my class would find it useful if the jbpm-console could automatically create, on start-up, a process global (e.g. processStartInfo?)  with some key fields similar to the ones you've linked to (e.g. initiator id, date/time etc). Do you think this is this a sufficiently common requirement that it would be worth me submitting a Jira request?

             

            Thanks again for getting back,

             

            Andy McC

            • 3. Re: How to know who has started a process?
              Mauricio Salatino Master

              Hi Andy,

              Maybe I wasn't clear enough. When I mention the "Currently Logged User" means the user logged in the application. If you are in a web application you can get that from the http session and your security framework as well. jBPM doesn't have that information for you, because that's application specific. In jBPM 5.4 you can do the same, you can provide your own ProcessListener that collect that information for you. Once again, notice that the Currently logged user is part of your application and how you handle security. How you know which user is executing each action in your app?

               

              Cheers

              1 of 1 people found this helpful
              • 4. Re: How to know who has started a process?
                Andy McC Newbie

                Hi Mauricio,

                 

                Don't worry - your answer was clear - it's because I'm new to a lot of the technologies surrounding jBPM and as a result I am probably asking a lot of naive and quite dumb questions!

                 

                I can see what you're saying about the info being application specific. In this case I'm not writing an app of my own, the app is jbpm-console and the user security is the default login process that comes with the 5.4.0.Final installation. My assumption was that with the user already logged in and the creation of new process instances being managed by jbpm-consle that it would be relatively easy to access the user's name. If I understand correctly, as jbpm-console is a web application then I should be able to do that by accessing the session info (although that's another learning curve I'll be sitting at the bottom of! ).

                 

                Thanks again - I do appreciate it,

                 

                Andy McC

                • 5. Re: How to know who has started a process?
                  Mauricio Salatino Master

                  Perfect Andy!

                  I'm not sure how is that working in the old jbpm console.. but you should do something similar. Just replace the current listener that probably is not storing the user that is logged in and store it. And then add that information in the process instance lists, like we are doing in the new console.

                   

                  Cheers

                  • 6. Re: How to know who has started a process?
                    Andy McC Newbie

                    Thanks again - although I'm meant to be using 5.4.0.Final I will take a look at the latest Console NG source and see how it's done.

                     

                    Looking forward to 6.0!

                     

                    Cheers

                    • 7. Re: How to know who has started a process?
                      antonio peña Newbie

                      Hi Mauricio, would it be possible to retrieve the process owner via runtimeDataService from the processEventListener? how should it be injected?

                      My implementation of afterProcessStarted method:

                      @Override

                        public void afterProcessStarted(ProcessStartedEvent pse) {

                        ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceById(pse.getProcessInstance().getId());

                        logger.debug("process " + pse.getProcessInstance().getProcessName() + " instanciated by "+ pi.getInitiator());

                        }

                      And i'm injection runtimeDataService as follows:

                      @Inject

                          private RuntimeDataService runtimeDataService;

                       

                      And i'm getting a nullpointerExcepcion