Channara
(Rin Channara)
21 August 2021 13:20
1
Hi All,
I tried to run data query resource:analytics.
But the result console undefined
my code below:
const myanalytic = {
results: {
resource: ‘analytics’,
params: {
dimension: [‘dx:y1gIMkQteQr’,‘pe:LAST_12_MONTHS’],
filter:‘ou:vUs2cBkPn50’
}
}
}
const { loading, error, data } = useDataQuery(myanalytic);
{console.log(“analytics:”+data)}
thank you
nnkogift
(Gift Nnko)
22 August 2021 07:29
2
Hello @Channara
Here is something that might help.
If the data of the useDataQuery
hook is undefined
, it either means it is still loading (loading == true) or there is an error with the query. The latter is most likely. You could try logging the error or loading to see if the query had issues or is still loading.
This is from the DHIS2 App Runtime Documentation
Regards.
Channara
(Rin Channara)
22 August 2021 09:44
3
Hi @nnkogift
I follow instruction step link, Yes it works fine for programs or indicators. But when i use resource:analytics. it show undefined.
nnkogift
(Gift Nnko)
22 August 2021 14:00
4
@Channara
What does console.log(error)
print?
Channara
(Rin Channara)
24 August 2021 02:13
5
Hi,
no error display.
but i use many useDataQuery hook in one function, can be that problem?
nnkogift
(Gift Nnko)
24 August 2021 11:00
6
Hello
Do you mean you use the useDataQuery
hook like this?
const Component = () =>{
const { data: data1, error: error1, loading: loading1} = useDataQuery(query1)
const { data:data2, error: error2, loading:loading2} = useDataQuery(query2)
...
}
This may work (assuming the variables for error, loading, and, data are not mixed up). There is a simpler way, however, of combining such queries. You could use only one useDataQuery
hook with the two queries passed in one object, they just need to have different keys. An example;
const queries = {
indicators: {
resource: 'indicators',
params: {
fields: ['id', 'displayName']
}
},
analytics: {
resource: 'analytics',
params: {
dimension: ['dx:y1gIMkQteQr', 'pe:LAST_12_MONTHS'],
filter: [
'ou:vUs2cBkPn50'
]
}
}
}
const Component = () =>{
const {error, loading, data} = useDataQuery(queries)
//data will contain an object of all your queries' results
}
Perhaps you could try implementing the queries this way and see if the problem is still there.
2 Likes
Channara
(Rin Channara)
25 August 2021 03:24
7
Yes, i use many useDataQuery, it doesn’t show any error, but the result is undefined.
when i combine in one useDataQuery, yes sure, it works fine.
many thank for supporting.
2 Likes