# How to retrieve tasks efficiently when constrained by value list?

**URL:** <https://forum.flowable.org/t/how-to-retrieve-tasks-efficiently-when-constrained-by-value-list/5134>\
**Category:** Flowable Engine\
**Created:** [December 23, 2019, 12:00pm UTC](https://forum.flowable.org/t/how-to-retrieve-tasks-efficiently-when-constrained-by-value-list/5134 "2019-12-23T12:00:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DarkStar1](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/darkstar1/32/394_2.png) [@DarkStar1](https://forum.flowable.org/u/DarkStar1)\
**Post date:** [December 23, 2019, 12:00pm UTC](https://forum.flowable.org/t/how-to-retrieve-tasks-efficiently-when-constrained-by-value-list/5134/1 "2019-12-23T12:00:03Z")

</div>

I want to supply a list of string Id values and create a task query that returns all active tasks wherein, every value is reflected in the process variable of the Returned task list. at the moment I have the following code:

```auto
        try {
            return bdoIds.stream().map(objId -> taskService.createTaskQuery().active()
                    .processVariableValueEquals("businessDomainObjectId", objId).includeProcessVariables().singleResult())
                    .collect(Collectors.toList());
        }
        catch (Exception ge){
            ge.printStackTrace()
            return Collections.emptyList();
        }
    }

```

Which seems terribly inefficient and will not scale very well at all.  
Can this be refactored such that I’m not executing a task query for every id?

---

<div class="post-metadata">

**Author:** ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)\
**Post date:** [December 23, 2019, 12:36pm UTC](https://forum.flowable.org/t/how-to-retrieve-tasks-efficiently-when-constrained-by-value-list/5134/2 "2019-12-23T12:36:58Z")

</div>

I don’t see anything like a `processVariableValueIn()` method, I’m afraid you may be stuck with `taskService.createNativeTaskQuery()` for this one.

> **[The Flowable API · Flowable Open Source Documentation](https://flowable.com/open-source/docs/bpmn/ch04-API/#query-api)**
>
> \## The Process Engine API and services
