Skip to main content
prasadm5595
April 8, 2023
Solved

Query Entity: fetchtotalcount is not working

  • April 8, 2023
  • 8 replies
  • 0 views

Dear Team,

Could someone help me to understand the below issue please.

I am trying to fetch the total count of the records from DB view. When I give fetchTotalCount=true it's throwing an error 'Expression evaluation error at function a!queryEntity [line 2]: An error occurred while retrieving the data. Details: Unexpected error executing query'. If I change the fetchTotalCount=false, it's working fine. Sample  code is below:

a!queryEntity(
entity: cons!DB_VIEWS_DSE,
query: a!query(
selection:
a!querySelection(
columns: a!queryColumn(
field: "id"
)
),
pagingInfo:
a!pagingInfo(
startIndex: 1,
batchSize: 1,
sort: {
a!sortInfo(field: "id", ascending: false())
}
)
),
fetchtotalcount: true
)

Best answer by peter.lewis

Keep in mind that the fetch total count is likely much slower than the operation to just get a single row too. I also question - why do you need to use a database view? Many of the capabilities of database views can now be supported through synced record types with record relationships, custom fields, and other records capabilities.

8 replies

stefanhelzle0001
Brainy
April 9, 2023

It seems like your query hits a database view. How long does the query take? To fetch the totalCount, Appian has to query the view twice. Once for the totalCount, second for the actual data. If a single query is just below the timeout, a second query will raise the bar.

prasadm5595
April 10, 2023

Hi Stefan, Thanks for the response. 

I agree with you. Two DB calls will happen if I used totalcount is true. But I am fetching only 1 record from DB and the total count of the table. Usually It should not take more than 3 to 4 sec. But my code taking around 8 to 10 sec to display the error message. I just really want to know how the fetchtotalcount will work internally. 

FYI, this is happening only for few DB views not all. Could you please help me to know what is the potential cause for fetching only one record and totalcount

stefanhelzle0001
Brainy
April 10, 2023

OK. Then your DB view is too slow. Appian has a timeout of 10 seconds. BTW, my timeout, as a user when waiting for a screen, is way lower.

What do you mean with "I just really want to know how the fetchtotalcount will work internally. "?

You will have to optimize that view.