Topic
11 replies Latest Post - ‏2012-10-11T02:28:43Z by SystemAdmin
shyenuganti
shyenuganti
40 Posts
ACCEPTED ANSWER

Pinned topic Querying the process instances for tasks using JS API

‏2012-10-05T18:06:28Z |
Is there any method to query the Process Instance to get the name of the activity on which it is waiting?

Like, if there is an intermediate message events and timer tasks inside the BPD and the BPD is waiting on an event, is there any JS method that can be used to get the name of the intermediate event on which the BPD is waiting during execution?

Or should we simply get all the tasks on the instance and check the status of each task to know this?

Do intermediate message events and timer events come into the "tasks" category on the process instance? Will the method TWProcesInstance.tasks return these events along with the human tasks?

Thanks,

Sri Harsha Yenuganti.
Updated on 2012-10-11T02:28:43Z at 2012-10-11T02:28:43Z by SystemAdmin
  • shyenuganti
    shyenuganti
    40 Posts
    ACCEPTED ANSWER

    Re: Querying the process instances for tasks using JS API

    ‏2012-10-08T15:19:36Z  in response to shyenuganti
    Can anyone help me in this ? Just trying to lift the thread !
    • AnthonyBpm
      AnthonyBpm
      390 Posts
      ACCEPTED ANSWER

      Re: Querying the process instances for tasks using JS API

      ‏2012-10-08T16:12:17Z  in response to shyenuganti
      First, timers and IME's are not considered "tasks" and you cannot grab that type of information from the JSAPI (to the best of my knowledge).

      Second, what you can grab is the list of tasks via:
      
      var zInstance = tw.system.findProcessInstanceByID(<insert_instance_id>); 
      // a TWProcessInstance object, argument is instance id 
      
      if(zInstance) 
      { var zTasks = zInstance.tasks; 
      // a native array of TWTask objects 
      
      for(var i=0;i<zTasks.length;i++) 
      { 
      // do what you want in here, per 
      } 
      }
      

      See also:
      TWProcess
      TWTask

      hth
      • shyenuganti
        shyenuganti
        40 Posts
        ACCEPTED ANSWER

        Re: Querying the process instances for tasks using JS API

        ‏2012-10-08T18:16:42Z  in response to AnthonyBpm
        Hi Anthony,

        I am able to query the human Tasks and System tasks same way as you outlined.. but not able to query the Intermediate Events..So JS API do not support querying the intermediate events for their status? Or querying a process to know on which event is it waiting or to get the exact location on the task pointer in the current execution flow of the BPD?
        • SystemAdmin
          SystemAdmin
          7615 Posts
          ACCEPTED ANSWER

          Re: Querying the process instances for tasks using JS API

          ‏2012-10-08T18:56:27Z  in response to shyenuganti
          I don't see that data anywhere in the JS-API. It might be in the details of the REST call where you get the Process Instance's execution details...

          Andrew Paier | Director of Special Operations | BP3 Global, Inc. www.bp-3.com
          • SystemAdmin
            SystemAdmin
            7615 Posts
            ACCEPTED ANSWER

            Re: Querying the process instances for tasks using JS API

            ‏2012-10-08T18:57:34Z  in response to SystemAdmin
            You might want to explain your use case and then someone who has seen something similar can post a suggested design pattern. Right now we can only speak to the tactical question you asked. Given more context we might be able to help you out more...

            Andrew Paier | Director of Special Operations | BP3 Global, Inc. www.bp-3.com
            • shyenuganti
              shyenuganti
              40 Posts
              ACCEPTED ANSWER

              Re: Querying the process instances for tasks using JS API

              ‏2012-10-08T19:22:48Z  in response to SystemAdmin
              Hi Andrew,

              Here is my scenario:

              I am trying to build some unit test framework that helps me to unit test the BPD much faster. My BPD has Intermediate events where it would be waiting for events. This BPD is long running process and will not come to an End state anytime soon. It will be waiting for events, responds to an event, go back and wait for events.

              I will start the process and send events as per the use case under test. And then query the BPD to know where it is waiting after consuming a set of events in a predetermined order. For this I am trying to use JS API to retrieve the position of the task pointer in the BPD after firing the events.

              Please let me know if you need any more information.
              • SystemAdmin
                SystemAdmin
                7615 Posts
                ACCEPTED ANSWER

                Re: Querying the process instances for tasks using JS API

                ‏2012-10-09T21:02:34Z  in response to shyenuganti
                Can you flip the problem on its head? Meaning can the test system determine what event the BPD should be waiting for given the data that went into the steps before hand (which I assume is part of the testing framework). Also, have you looked at the REST API call?

                Andrew Paier | Director of Special Operations | BP3 Global, Inc. www.bp-3.com
                • shyenuganti
                  shyenuganti
                  40 Posts
                  ACCEPTED ANSWER

                  Re: Querying the process instances for tasks using JS API

                  ‏2012-10-10T14:36:19Z  in response to SystemAdmin
                  Even then we have to query the BPD whether it is actually waiting for the event or not without seeing it visually in the Process Inspector. We need the JS API for that, if it exists. I tried the REST API but it is becoming hard to keep track of the snapshot id's of the BPD's. The BPM is aassigning a new snapshot id to the processes for every change we do on it. And this snapshot id is used in the API call. I think the REST API would be fine when the BPD is finalized and there are no more changes where the snapshot would remain constant. Correct me if I am wrong :)
                  • SystemAdmin
                    SystemAdmin
                    7615 Posts
                    ACCEPTED ANSWER

                    Re: Querying the process instances for tasks using JS API

                    ‏2012-10-10T15:04:33Z  in response to shyenuganti
                    The "Current State" call on the REST API only asks for the instance ID you are querying… What call are you using?

                    Andrew Paier | Director of Special Operations | BP3 Global, Inc. www.bp-3.com
                    • shyenuganti
                      shyenuganti
                      40 Posts
                      ACCEPTED ANSWER

                      Re: Querying the process instances for tasks using JS API

                      ‏2012-10-10T15:14:14Z  in response to SystemAdmin
                      The current state uses the instance id. But the REST API for starting a BPD uses the snapshot id. I am trying to do everything in one API either REST API or JS API. Not mixing both of them in the solution.
                      • SystemAdmin
                        SystemAdmin
                        7615 Posts
                        ACCEPTED ANSWER

                        Re: Querying the process instances for tasks using JS API

                        ‏2012-10-11T02:28:43Z  in response to shyenuganti
                        For the REST API call to start an instance the snapshotId is optional. If you do not supply a snapshot ID then it uses the default snapshot of the Process App. On the Process Center this should be Tip. On a runtime server you can indicate the default snapshot. If you deploy using inflight migration, the new snapshot should be made the default. When no snapshot is indicated the behavior is essentially the same as a Start Messge Event.

                        Andrew Paier | Director of Special Operations | BP3 Global, Inc. www.bp-3.com