# How to set an output variable for a service task

**URL:** <https://forum.flowable.org/t/how-to-set-an-output-variable-for-a-service-task/9785>\
**Category:** Flowable Engine\
**Created:** [October 7, 2022, 12:45pm UTC](https://forum.flowable.org/t/how-to-set-an-output-variable-for-a-service-task/9785 "2022-10-07T12:45:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pushkala](https://avatars.discourse-cdn.com/v4/letter/p/db5fbb/32.png) [@Pushkala](https://forum.flowable.org/u/Pushkala)\
**Post date:** [October 7, 2022, 12:45pm UTC](https://forum.flowable.org/t/how-to-set-an-output-variable-for-a-service-task/9785/1 "2022-10-07T12:45:54Z")

</div>

Hi team,  
I was modelling a service task in flowable. I need to do some custom logic in a java class (to fetch a list of task names from database based on user form input) and set result of this as an output variable of the service task and show that in history.  
Could you please guide me for achieving the same

Thanks in advance

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [October 12, 2022, 10:29am UTC](https://forum.flowable.org/t/how-to-set-an-output-variable-for-a-service-task/9785/2 "2022-10-12T10:29:50Z")

</div>

You can use `execution.setVariable(name, value)` in the service task logic for this purpose.
