My goal is to query the resultRecordCount with returnDistinctValues = true with one output field. Reason is because the result is sometimes more than 1000 and I need to paginate the queries and I can't do that without knowing the total number of distinct results.
If you use executeForCount, then the returnDistinctValues will work to let you know if the map services MaxRecordCount is high enough to work with one query.
I think this is actually a bug. Here's a distinct query on a 10.5.1 service that returns 881 records with count but 534 without count. A similar query on a 10.6.1 service returns the same number of distinct records with and without count. Doesn't seem to matter if I do executeForCount or resultRecordCount.
Esri Support was able to replicate the issue and created
BUG-000117336 : The "returnDistinctValues" parameter is ignored when querying a ArcGIS Server 10.6 service with "resultRecordCount" / "Return Count only" parameter.
The development team will be reviewing the bug and will provide us further updates. The issue is not reproducible in the latest release of ArcGIS Server 10.6.1 and can be used as a workaround.