Topic
  • 17 replies
  • Latest Post - ‏2013-08-06T20:56:48Z by AndrewPaier
rodrigo.gonzalez
rodrigo.gonzalez
18 Posts

Pinned topic START PROCESS AUTOMATICALLY

‏2013-07-17T14:20:42Z |

Hi everyone.

I was checking some examples i found in IBM BPM docs, the thing is that i have one process app with tu bpd's, the first is my process of "Recuperación" and the second is my process of "Conciliación", at the end of Recuperación i have a system task, in this task use tw.system.startProcessByName instruction using the variables of my first process, achieving the second process run automatically.

 
As I wrote at the beginning these two processes are within the same application and working properly, my question is:
 
This can be done but having the processes in different applications?
 
For example Application "Appli1" with the process "Recovery" and the app "Appli2" with the process "Reconciliation."
 
If possible how could I achieve this execution?
 
Thanks in advance for your kind help.
 
Greetings.
  • kolban
    kolban
    3322 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-07-17T16:38:10Z  

    Looking at 8.5, it seems to me that if one can obtain a TWProcess object, it has a method called "startNew" which will start a new instance.

    We can get a TWProcess from an instance of TWProcessAppSnapshot and using its findProcessByName() method.

    We can get a TWProcessAppSnapshot from TWProcessApp.currentSnapshot.

    We can get a TWProcessApp from tw,system.model.findProcessAppByName().

    So ... working backwards ... if we want to execute process P from Process App S.

    We find TWProcessApp for S.

    We find the corresponding Snapshot which contains the process.

    We find a reference to the process template from the snapshot.

    We create a new instance of the process from process model template reference.

  • rodrigo.gonzalez
    rodrigo.gonzalez
    18 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-07-17T16:59:11Z  
    • kolban
    • ‏2013-07-17T16:38:10Z

    Looking at 8.5, it seems to me that if one can obtain a TWProcess object, it has a method called "startNew" which will start a new instance.

    We can get a TWProcess from an instance of TWProcessAppSnapshot and using its findProcessByName() method.

    We can get a TWProcessAppSnapshot from TWProcessApp.currentSnapshot.

    We can get a TWProcessApp from tw,system.model.findProcessAppByName().

    So ... working backwards ... if we want to execute process P from Process App S.

    We find TWProcessApp for S.

    We find the corresponding Snapshot which contains the process.

    We find a reference to the process template from the snapshot.

    We create a new instance of the process from process model template reference.

    but in 7.5.1 can I do something similar? because my environment is in that version

  • atummidi
    atummidi
    41 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-07-17T16:59:29Z  

    Hi, another way to achieve this even in earlier versions...

    use "Read from HTTP" integration service from System Data.. This is for running a rest api from inside a service.

    We have a rest api to start any process irrespective of its location.

  • kolban
    kolban
    3322 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-07-17T17:08:33Z  
    • atummidi
    • ‏2013-07-17T16:59:29Z

    Hi, another way to achieve this even in earlier versions...

    use "Read from HTTP" integration service from System Data.. This is for running a rest api from inside a service.

    We have a rest api to start any process irrespective of its location.

    Given a choice, if there are JavaScript functions that can be used from a server side script I would use those over HTTP requests.  HTTP requests were designed to be used from a client application like a browser.  Using REST requests usually means having to hard-code a userid/password pair so that the request is authenticated.

  • kolban
    kolban
    3322 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-07-17T17:09:24Z  

    but in 7.5.1 can I do something similar? because my environment is in that version

    The answer is "probably".  Given what you now know about the "concepts" involved, open up the InfoCenter for 7.5.1 and see if the same JavaScript objects exist and have the same or similar methods.

  • rodrigo.gonzalez
    rodrigo.gonzalez
    18 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-07-17T19:07:27Z  
    • kolban
    • ‏2013-07-17T16:38:10Z

    Looking at 8.5, it seems to me that if one can obtain a TWProcess object, it has a method called "startNew" which will start a new instance.

    We can get a TWProcess from an instance of TWProcessAppSnapshot and using its findProcessByName() method.

    We can get a TWProcessAppSnapshot from TWProcessApp.currentSnapshot.

    We can get a TWProcessApp from tw,system.model.findProcessAppByName().

    So ... working backwards ... if we want to execute process P from Process App S.

    We find TWProcessApp for S.

    We find the corresponding Snapshot which contains the process.

    We find a reference to the process template from the snapshot.

    We create a new instance of the process from process model template reference.

    Well... for example I enter to REST API TESTER and the with the information of my process I start a process from the tester, and it was succes.

    After te execution the tester shows the request to start the process, in this case the request was:

    http://localhost:9080/rest/bpm/wle/v1/process?action=start&bpdId=25.88d8888b-5459-482f-ba42-38ceb2166f6b&processAppId=2066.8cf47412-8e3e-4563-bad3-e55dca5823ed&parts=all

    But when I copy this url and try to run it directly in the browser, nothing happens, is there a diferent kind to execute te request in an url from the browser???

    And how can I execute this from a BPM task??

    Really Thanks for your help!!

  • A.A.A
    A.A.A
    29 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-07-17T19:27:09Z  

    Well... for example I enter to REST API TESTER and the with the information of my process I start a process from the tester, and it was succes.

    After te execution the tester shows the request to start the process, in this case the request was:

    http://localhost:9080/rest/bpm/wle/v1/process?action=start&bpdId=25.88d8888b-5459-482f-ba42-38ceb2166f6b&processAppId=2066.8cf47412-8e3e-4563-bad3-e55dca5823ed&parts=all

    But when I copy this url and try to run it directly in the browser, nothing happens, is there a diferent kind to execute te request in an url from the browser???

    And how can I execute this from a BPM task??

    Really Thanks for your help!!

    Hey,

     

    Take a look at this link: http://pic.dhe.ibm.com/infocenter/dmndhelp/v7r5m1/index.jsp?topic=%2Fcom.ibm.wbpm.ref.doc%2Fjavascript%2FJSAPI.html

    This is the javascript API reference Neil was talking about. In there you could locate the different API's you need to achieve you're task within the service (BPM Task). How you execute it depends on the context of your process logic.

    As for the REST tester, you should probably only use it if you were attempting to leverage restAPI's, which I believe you may not have to do to start your process.

  • kolban
    kolban
    3322 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-07-17T19:48:14Z  

    Well... for example I enter to REST API TESTER and the with the information of my process I start a process from the tester, and it was succes.

    After te execution the tester shows the request to start the process, in this case the request was:

    http://localhost:9080/rest/bpm/wle/v1/process?action=start&bpdId=25.88d8888b-5459-482f-ba42-38ceb2166f6b&processAppId=2066.8cf47412-8e3e-4563-bad3-e55dca5823ed&parts=all

    But when I copy this url and try to run it directly in the browser, nothing happens, is there a diferent kind to execute te request in an url from the browser???

    And how can I execute this from a BPM task??

    Really Thanks for your help!!

    Again, I'd suggest disuading you from using REST APIs within the run-time if there are JavaScript options available.  For your specific post, I can think of two issues.

    The first is probably the one that bit you.  When making a REST request, you specify an HTTP command such as GET, PUT, POST, DELETE etc.  You can't do this by entering a URL in the browser.  The browser ONLY makes GET requests from a URL entry.  I suspect if you look up the documentation on the REST request you are making it will say that it must be either PUT or POST.

    The second issue is one of authentication.  If you open up a virgin browser and make a REST request, who is that request being made as?

    Neil

  • dogren@gmail.com
    dogren@gmail.com
    421 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-07-17T20:11:01Z  

    So obviously there have been lots of valid technical answers in this thread.

    But, I'd ask, why do you want to put them in separate apps? Generally, if you want one to call the other, my first impression would be that they should be in the same app.

    Also, I'd suggest that if you do want them in different apps it is usually because you want them to be loosely coupled. That, combined with my dislike of startProcessByName, would lead me towards the direction of starting the process the way you would expose any process: expose it a UCA within the target process app and then invoke that web service within the calling process app. That gives you a lot more control over versioning and interfaces. And that level of abstraction gives you a lot more control to handle situations where you want to change the inputs of a process. If you use startProcessByName (or the API equivalent) and the process name changes, or the input args change, you are in trouble. An abstraction layer could help with that.

    David

  • rodrigo.gonzalez
    rodrigo.gonzalez
    18 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-07-18T13:52:19Z  
    • kolban
    • ‏2013-07-17T19:48:14Z

    Again, I'd suggest disuading you from using REST APIs within the run-time if there are JavaScript options available.  For your specific post, I can think of two issues.

    The first is probably the one that bit you.  When making a REST request, you specify an HTTP command such as GET, PUT, POST, DELETE etc.  You can't do this by entering a URL in the browser.  The browser ONLY makes GET requests from a URL entry.  I suspect if you look up the documentation on the REST request you are making it will say that it must be either PUT or POST.

    The second issue is one of authentication.  If you open up a virgin browser and make a REST request, who is that request being made as?

    Neil

    Neil.

    First, thanks for your comments, I execute my url from an application that simulate the POST method and the process start as I want, now i want to implement that in a BPM coach the fist thing i do was in a Custom  HTML control i put this code:

     

    <html>
        <script type="text/javascript">
    function proceed () {
        var form = document.createElement('form');
        form.setAttribute('method', 'post');
        form.setAttribute('action', 'http://localhost:9080/rest/bpm/wle/v1/process?action=start&bpdId=25.88d8888b-5459-482f-ba42-38ceb2166f6b&processAppId=2066.8cf47412-8e3e-4563-bad3-e55dca5823ed&parts=all');
        form.submit();
        history.back();
    }
    </script>
     
     
    <button type="button" onclick="proceed();">do</button> 
        </html>

     

    And effectively mi process start as I want, but now what i want to do is execute it after click a coach button so what I put a server script and then wrote this part of code:

     

        var form = document.createElement('form');
        form.setAttribute('method', 'post');
        form.setAttribute('action', 'http://localhost:9080/rest/bpm/wle/v1/process?action=start&bpdId=25.88d8888b-5459-482f-ba42-38ceb2166f6b&processAppId=2066.8cf47412-8e3e-4563-bad3-e55dca5823ed&parts=all');
        form.submit();

     

    But at the time i execute mi coach and press coach button I recieve this error message:

     

    Runtime error in script ("Process: '1' ProcessItem: 'Untitled2' Type: 'ITEM'" 2:0).ReferenceError: "document" is not defined. (#2)
    Script (line 2):
       1 : 
       2 :     var form = document.createElement('form');
       3 :     form.setAttribute('method', 'post');
       4 :     form.setAttribute('action', 'http://localhost:9080/rest/bpm/wle/v1/process?action=start&bpdId=25.88d8888b-5459-482f-ba42-38ceb2166f6b&processAppId=2066.8cf47412-8e3e-4563-bad3-e55dca5823ed&parts=all');

     

    So I really apreciate if someone can help me or tell me what im doing wrong.

    Thanks a lot to everyone!!

  • kolban
    kolban
    3322 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-07-18T14:11:18Z  

    Neil.

    First, thanks for your comments, I execute my url from an application that simulate the POST method and the process start as I want, now i want to implement that in a BPM coach the fist thing i do was in a Custom  HTML control i put this code:

     

    <html>
        <script type="text/javascript">
    function proceed () {
        var form = document.createElement('form');
        form.setAttribute('method', 'post');
        form.setAttribute('action', 'http://localhost:9080/rest/bpm/wle/v1/process?action=start&bpdId=25.88d8888b-5459-482f-ba42-38ceb2166f6b&processAppId=2066.8cf47412-8e3e-4563-bad3-e55dca5823ed&parts=all');
        form.submit();
        history.back();
    }
    </script>
     
     
    <button type="button" onclick="proceed();">do</button> 
        </html>

     

    And effectively mi process start as I want, but now what i want to do is execute it after click a coach button so what I put a server script and then wrote this part of code:

     

        var form = document.createElement('form');
        form.setAttribute('method', 'post');
        form.setAttribute('action', 'http://localhost:9080/rest/bpm/wle/v1/process?action=start&bpdId=25.88d8888b-5459-482f-ba42-38ceb2166f6b&processAppId=2066.8cf47412-8e3e-4563-bad3-e55dca5823ed&parts=all');
        form.submit();

     

    But at the time i execute mi coach and press coach button I recieve this error message:

     

    <pre align="left" class="errormsg" dir="ltr" style="font-family: verdana; font-size: 10px; color: rgb(0, 0, 0); background-color: rgb(230, 236, 242);"> Runtime error in script ("Process: '1' ProcessItem: 'Untitled2' Type: 'ITEM'" 2:0).ReferenceError: "document" is not defined. (#2) Script (line 2): 1 : 2 : var form = document.createElement('form'); 3 : form.setAttribute('method', 'post'); 4 : form.setAttribute('action', 'http://localhost:9080/rest/bpm/wle/v1/process?action=start&bpdId=25.88d8888b-5459-482f-ba42-38ceb2166f6b&processAppId=2066.8cf47412-8e3e-4563-bad3-e55dca5823ed&parts=all');</pre>

     

    So I really apreciate if someone can help me or tell me what im doing wrong.

    Thanks a lot to everyone!!

    Unfortunately, it is going to be nowhere near as easy as that.  An HTTP Form POST is nowhere near the same as an AJAX REST call.  What you will need to do is use a JavaScript toolkit such as Dojo in order to perform the REST call.

    The final answer will be found here:

    http://dojotoolkit.org/reference-guide/1.7/quickstart/ajax.html

    But you will really, really need to be comfortable with JavaScript, REST, AJAX, JSON and DOJO before you go down this path.

    Neil

  • rodrigo.gonzalez
    rodrigo.gonzalez
    18 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-07-22T13:51:55Z  
    • kolban
    • ‏2013-07-18T14:11:18Z

    Unfortunately, it is going to be nowhere near as easy as that.  An HTTP Form POST is nowhere near the same as an AJAX REST call.  What you will need to do is use a JavaScript toolkit such as Dojo in order to perform the REST call.

    The final answer will be found here:

    http://dojotoolkit.org/reference-guide/1.7/quickstart/ajax.html

    But you will really, really need to be comfortable with JavaScript, REST, AJAX, JSON and DOJO before you go down this path.

    Neil

    Hi Neil.

    Thanks for your reply, I was checking some example about how can I do that, the this is that I made a java integration to perform de actions that I want bmp do.

    I attached my java file I developed, as you can see in the code I'm defining a URL to perform a POST and start automatically the desired process after execution.
     
    As an example has served me well but what I want to do is the following.
     
    As I had commented that I want to start the process is in a different application that is why I use the rest api to start the process,  from my main process I have to pass parameters to start the new process, I have reviewed the documentation and have read that can determine the parameters within the same url.

    My idea is to create a variable at the end of my main process, in which I can set parameters based on what variables containing, in simple words I want to build the url from my bpm, save in a variable and then send it to my java integration service to take this variable and perform its execution, is this possible?

    Thanks in advance.

    Attachments

  • rodrigo.gonzalez
    rodrigo.gonzalez
    18 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-07-23T14:40:50Z  

    Hi Neil.

    Thanks for your reply, I was checking some example about how can I do that, the this is that I made a java integration to perform de actions that I want bmp do.

    I attached my java file I developed, as you can see in the code I'm defining a URL to perform a POST and start automatically the desired process after execution.
     
    As an example has served me well but what I want to do is the following.
     
    As I had commented that I want to start the process is in a different application that is why I use the rest api to start the process,  from my main process I have to pass parameters to start the new process, I have reviewed the documentation and have read that can determine the parameters within the same url.

    My idea is to create a variable at the end of my main process, in which I can set parameters based on what variables containing, in simple words I want to build the url from my bpm, save in a variable and then send it to my java integration service to take this variable and perform its execution, is this possible?

    Thanks in advance.

    I can resolve my problem.

    https://www.ibm.com/developerworks/community/forums/html/topic?id=d5357c82-17fd-4de1-b0fd-6e274dfd44d7#53c8825d-aa7e-4dba-9ce2-e56c11c167aa

    Thanks, to everyone for your coments.

  • AndrewPaier
    AndrewPaier
    832 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-08-01T01:12:53Z  

    Feels like this thread went the really long way around the block.  The easiest way to do this would be to put the 2 processes in to the 2 process apps then create a shared Toolkit.  The TK has a UCA in it with the payload (inputs and outputs) being the process data.  PA A invokes the UCA, PA B has a start message event listener that listens for the invocation of the UCA and starts a new instance of the process In PA B when it is invoked.

    This feels much more straight forward to me than the other suggestions using API calls...

    Andrew Paier  |  Director  |  BP3 Global, Inc.
    BP3 Global's Website  |  Twitter  |  Linkedin  |  Google+  |  Blogs

  • CraigKitching
    CraigKitching
    26 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-08-01T21:19:54Z  
    • kolban
    • ‏2013-07-17T16:38:10Z

    Looking at 8.5, it seems to me that if one can obtain a TWProcess object, it has a method called "startNew" which will start a new instance.

    We can get a TWProcess from an instance of TWProcessAppSnapshot and using its findProcessByName() method.

    We can get a TWProcessAppSnapshot from TWProcessApp.currentSnapshot.

    We can get a TWProcessApp from tw,system.model.findProcessAppByName().

    So ... working backwards ... if we want to execute process P from Process App S.

    We find TWProcessApp for S.

    We find the corresponding Snapshot which contains the process.

    We find a reference to the process template from the snapshot.

    We create a new instance of the process from process model template reference.

    This looks to be pretty easy in 7.5.1, unless this wouldn't work for some reason, here's the script:

     

    tw.system.model.findProcessAppByName(processAppName).currentSnapshot.findProcessByName(processName).startNew(inputParams);

  • CraigKitching
    CraigKitching
    26 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-08-01T21:20:10Z  

    tw.system.model.findProcessAppByName(processAppName).currentSnapshot.findProcessByName(processName).startNew(inputParams);

     

    I believe.

  • AndrewPaier
    AndrewPaier
    832 Posts

    Re: START PROCESS AUTOMATICALLY

    ‏2013-08-06T20:56:48Z  

    tw.system.model.findProcessAppByName(processAppName).currentSnapshot.findProcessByName(processName).startNew(inputParams);

     

    I believe.

    Another good option

    Andrew Paier  |  Director  |  BP3 Global, Inc.
    BP3 Global's Website  |  Twitter  |  Linkedin  |  Google+  |  Blogs