I have a web application with a Query widget that is pointing to a REST service point layer. The layer is NOT in the map, and will only display the results of a query. The users will be able to perform a spatial query on the layer, but first I want to filter the data via an SQL expression or esri QueryTask so that only a subset of the data is available for the spatial query, if this makes any sense. I can't do a definition query in the mxd because the data get updated regularly, so this needs to be dynamic. Basically I want to look at all of the numbers in a particular field, find the largest number (or most recent batch) and use that number to plug in to the SQL Expression in the TaskSetting.js file (or if there is an SQL property that would do the same thing at the time of the query). This way, when the user performs the spatial query, they will only be querying the latest batch numbers and not the entire dataset. I tried using QueryTask, but this returns feature sets, not the value, and I can't seem to figure out if there is a way to set the where statement to filter out all features except the ones with the highest value in the "Batch" field. I can hard code the expression with the correct value (see line 19), but then I have to update the value every time the data is updated on the server!
_getWhereInfo<SPAN class="punctuation token">:</SPAN> <SPAN class="keyword token">function</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> result <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN>
status<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">0</SPAN><SPAN class="punctuation token">,</SPAN>
where<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">""</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>askForValues<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN>
<SPAN class="keyword token">var</SPAN> newExpr <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">this</SPAN><SPAN class="punctuation token">.</SPAN>filterParams<SPAN class="punctuation token">.</SPAN><SPAN class="token function">getFilterExpr</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">var</SPAN> validExpr <SPAN class="operator token">=</SPAN> newExpr <SPAN class="operator token">&&</SPAN> <SPAN class="keyword token">typeof</SPAN> newExpr <SPAN class="operator token">===</SPAN> <SPAN class="string token">'string'</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="keyword token">if</SPAN><SPAN class="punctuation token">(</SPAN>validExpr<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN>
result<SPAN class="punctuation token">.</SPAN>status <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">;</SPAN>
result<SPAN class="punctuation token">.</SPAN>where <SPAN class="operator token">=</SPAN> newExpr<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">{</SPAN>
result<SPAN class="punctuation token">.</SPAN>status <SPAN class="operator token">=</SPAN> <SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">;</SPAN>
result<SPAN class="punctuation token">.</SPAN>where <SPAN class="operator token">=</SPAN> <SPAN class="keyword token">null</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">{</SPAN>
result<SPAN class="punctuation token">.</SPAN>status <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="comment token">//result.where = this.currentAttrs.config.filter.expr;</SPAN>
result<SPAN class="punctuation token">.</SPAN>where <SPAN class="operator token">=</SPAN> <SPAN class="string token">"Batch = 20"</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="comment token">//value hard coded</SPAN>
<SPAN class="comment token">//console.log("where expression ", result.where);</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">if</SPAN><SPAN class="punctuation token">(</SPAN>result<SPAN class="punctuation token">.</SPAN>status <SPAN class="operator token">===</SPAN> <SPAN class="number token">1</SPAN> <SPAN class="operator token">&&</SPAN> <SPAN class="operator token">!</SPAN>result<SPAN class="punctuation token">.</SPAN>where<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">{</SPAN>
result<SPAN class="punctuation token">.</SPAN>where <SPAN class="operator token">=</SPAN> <SPAN class="string token">"1=1"</SPAN><SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN>
<SPAN class="keyword token">return</SPAN> result<SPAN class="punctuation token">;</SPAN>
<SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN> I tried using "Batch = Max(Batch)" and a few variations, but no luck so far! Maybe I am going about this all wrong?