# Combining multiple queries using the DHIS2 adaptor

**URL:** <https://community.openfn.org/t/combining-multiple-queries-using-the-dhis2-adaptor/104>\
**Category:** Adaptors & Templates\
**Created:** [June 16, 2021, 8:28pm UTC](https://community.openfn.org/t/combining-multiple-queries-using-the-dhis2-adaptor/104 "2021-06-16T20:28:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsurrao](https://community.openfn.org/letter_avatar_proxy/v4/letter/d/50afbb/32.png) [@dsurrao](https://community.openfn.org/u/dsurrao)\
**Post date:** [June 16, 2021, 8:28pm UTC](https://community.openfn.org/t/combining-multiple-queries-using-the-dhis2-adaptor/104/1 "2021-06-16T20:28:02Z")

</div>

I need to fetch data element values and their associated data element definitions using the language-dhis2 adaptor. Is the snippet below correct syntax, and would the resulting state include both result sets?

When I ran this script, state seemed to only include results of the second operation.

```
getDataValues({
    orgUnit: 'plPz2j9VSIz',
    period: '202105',
    dataSet: 'IBhezUyCB5Q',
    limit: 2,
});

getMetadata(['dataElements'], {
    filters: ['dataSetElements.dataSet.id:eq:IBhezUyCB5Q'],
});

console.log(state);

```

---

<div class="post-metadata">

**Author:** ![chaiwa](https://community.openfn.org/user_avatar/community.openfn.org/chaiwa/32/33_2.png) [@chaiwa](https://community.openfn.org/u/chaiwa)\
**Post date:** [June 17, 2021, 1:12am UTC](https://community.openfn.org/t/combining-multiple-queries-using-the-dhis2-adaptor/104/2 "2021-06-17T01:12:56Z")

</div>

> [@dsurrao](#):
>
> ```auto
> getDataValues({
> orgUnit: 'plPz2j9VSIz',
> period: '202105',
> dataSet: 'IBhezUyCB5Q',
> limit: 2,
> });
> 
> getMetadata(['dataElements'], {
> filters: ['dataSetElements.dataSet.id:eq:IBhezUyCB5Q'],
> });
> 
> console.log(state);
> 
> ```

@dsurrao You are only seeing the results of the second operation because **state.data** only contains the results of the **last run operation** for a given job. If you want to inspect how each operation **modifies state** , you would also want to check what gets stored in **state.references** (this kinda keeps a list of results of each operation in a given job).

So for this job, try putting the console logs as below and inspect the results:

```
console.log('state.data',state.data);
console.log('state.references',state.references);
getDataValues({
    orgUnit: 'plPz2j9VSIz',
    period: '202105',
    dataSet: 'IBhezUyCB5Q',
    limit: 2,
});

console.log('state.data',state.data);
console.log('state.references',state.references);

getMetadata(['dataElements'], {
    filters: ['dataSetElements.dataSet.id:eq:IBhezUyCB5Q'],
});

console.log('state.data',state.data);
console.log('state.references',state.references);

```

---

<div class="post-metadata">

**Author:** ![dsurrao](https://community.openfn.org/letter_avatar_proxy/v4/letter/d/50afbb/32.png) [@dsurrao](https://community.openfn.org/u/dsurrao)\
**Post date:** [June 17, 2021, 4:18pm UTC](https://community.openfn.org/t/combining-multiple-queries-using-the-dhis2-adaptor/104/3 "2021-06-17T16:18:15Z")

</div>

Thanks @chaiwa, this is very helpful!
