How to set an output variable for a service task

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

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