# How to write on database at the end of a process? \[SOLVED\]

**URL:** <https://community.ofelia.com/t/how-to-write-on-database-at-the-end-of-a-process-solved/6912>\
**Category:** Q&A\
**Created:** [29 January 2016 08:30 UTC](https://community.ofelia.com/t/how-to-write-on-database-at-the-end-of-a-process-solved/6912 "2016-01-29T08:30:32Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![davide.abati](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@davide.abati](https://community.ofelia.com/u/davide.abati)\
**Post date:** [29 January 2016 08:30 UTC](https://community.ofelia.com/t/how-to-write-on-database-at-the-end-of-a-process-solved/6912/1 "2016-01-29T08:30:32Z")

</div>

Hi, I am using Bonita BPM and i developed an API extension. I also added a postgres db storing business data (products and so), leaving to Bonita the process handling.  
My environment involves two processes:

- the main process
- a subprocess

My issue is the following:  
what’s the right way to trigger an update to **my database** each time the subprocess instance is completed? I would like to, say, change the state of the product involved in the subprocess.

From the documentation, I can’t get whether I should make use of a connector or a event handler, or something else.

Thank you for your help

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [29 January 2016 08:34 UTC](https://community.ofelia.com/t/how-to-write-on-database-at-the-end-of-a-process-solved/6912/2 "2016-01-29T08:34:16Z")

</div>

I always use a connector. much easier…

regards  
Seán

_PS: If this reply answers your question, please mark a resolved._

---

<div class="post-metadata">

**Author:** ![system](https://europe1.discourse-cdn.com/flex013/uploads/community_bonitasoft/original/2X/6/6b7b18c0478f2645369e82e009b65e3b97f2cc12.svg) [@system](https://community.ofelia.com/u/system)\
**Post date:** [29 January 2016 09:19 UTC](https://community.ofelia.com/t/how-to-write-on-database-at-the-end-of-a-process-solved/6912/3 "2016-01-29T09:19:08Z")

</div>

If your “product” is stored using Bonita BPM Business Data feature the way to go is to define a service task at the end of the sub process and on the service task define an operation.

If you use an external database (not managed by Business Data) I suggest to use a database connector as recommended by Sean. Use the data source connector with a connection pool configuration to ensure performance.

---

<div class="post-metadata">

**Author:** ![davide.abati](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@davide.abati](https://community.ofelia.com/u/davide.abati)\
**Post date:** [29 January 2016 09:29 UTC](https://community.ofelia.com/t/how-to-write-on-database-at-the-end-of-a-process-solved/6912/4 "2016-01-29T09:29:31Z")

</div>

Thank you antoine, I think a database connector is the win. I have now the issue of customizing my query based on the process variables. I explained it better answering Sean

---

<div class="post-metadata">

**Author:** ![davide.abati](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@davide.abati](https://community.ofelia.com/u/davide.abati)\
**Post date:** [29 January 2016 09:27 UTC](https://community.ofelia.com/t/how-to-write-on-database-at-the-end-of-a-process-solved/6912/5 "2016-01-29T09:27:55Z")

</div>

Thank you Sean. I’m configuring the connector out for the final subprocess activity right now. How can i use the subprocess variables to customize my query? Let’s say i have a process variable “product\_id” and i want to update the record like “UPDATE products SET state=‘completed’ WHERE product\_id = (%product\_id)”.

---

<div class="post-metadata">

**Author:** ![Sean\_McP](https://dub1.discourse-cdn.com/flex013/user_avatar/community.ofelia.com/sean_mcp/32/932_2.png) [@Sean\_McP](https://community.ofelia.com/u/Sean_McP)\
**Post date:** [29 January 2016 10:58 UTC](https://community.ofelia.com/t/how-to-write-on-database-at-the-end-of-a-process-solved/6912/6 "2016-01-29T10:58:33Z")

</div>

I think your statement should be:

UPDATE products SET state=‘completed’ WHERE product\_id = {$product\_id}

this will do the substitution,

Or to save doing a single call per subprocess you could do something like as shown here using a script connector:

[http://community.ofelia.com/answer-how-batch-insert-2#comment-1690](http://community.ofelia.com/answer-how-batch-insert-2#comment-1690)

regards  
Seán

---

<div class="post-metadata">

**Author:** ![davide.abati](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@davide.abati](https://community.ofelia.com/u/davide.abati)\
**Post date:** [29 January 2016 11:15 UTC](https://community.ofelia.com/t/how-to-write-on-database-at-the-end-of-a-process-solved/6912/7 "2016-01-29T11:15:00Z")

</div>

Thank you, it worked!
