I have a standalone table in an ArcGIS rest service that I need to query. The service has security requiring a username and password. I used this table in 10.2.6 applications using credentials and querytask without a problem. Is there a way in runtime to query this table? Do I have to use NetworkRequest, which is more complicated with tokens?
You can do that with a ServiceFeatureTable. This sample showcases this with a feature layer for viewing, but you don't need to display it - you could just query the ServiceFeatureTable directly - arcgis-runtime-samples-qt/ArcGISRuntimeSDKQt_QMLSamples/Features/FeatureLayer_Query at master · Esri/arcgis-runtime-samp…
As for the authorization component, you can do that a few ways. You can create a Credential object with username and password, and set that on the ServiceFeatureTable. You could also use the AuthenticationManager workflow, which is discussed here - Access the ArcGIS platform—ArcGIS Runtime SDK for Qt | ArcGIS for Developers
Hi Lucas,
That was the first thing I tried and apparently since the table has no geometry that doesn't work.
Tables with no geometry should work. Here is an example:
<SPAN class="keyword token">import</SPAN> QtQuick <SPAN class="number token">2.6</SPAN> <SPAN class="keyword token">import</SPAN> QtQuick<SPAN class="punctuation token">.</SPAN>Controls <SPAN class="number token">2.2</SPAN> <SPAN class="keyword token">import</SPAN> Esri<SPAN class="punctuation token">.</SPAN>ArcGISRuntime <SPAN class="number token">100.6</SPAN> ApplicationWindow <SPAN class="punctuation token">{</SPAN> id<SPAN class="punctuation token">:</SPAN> appWindow width<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">800</SPAN> height<SPAN class="punctuation token">:</SPAN> <SPAN class="number token">600</SPAN> title<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"Untitled81"</SPAN> ServiceFeatureTable <SPAN class="punctuation token">{</SPAN> url<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"https://services2.arcgis.com/ZQgQTuoyBrtmoGdP/arcgis/rest/services/AlaskaNationalParksPreservesSpecies_List/FeatureServer/2"</SPAN> Component<SPAN class="punctuation token">.</SPAN>onCompleted<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="token function">load</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">}</SPAN> onLoadStatusChanged<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>loadStatus <SPAN class="operator token">===</SPAN> Enums<SPAN class="punctuation token">.</SPAN>LoadStatusLoaded<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"loaded"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="token function">queryFeatures</SPAN><SPAN class="punctuation token">(</SPAN>params<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> onQueryFeaturesStatusChanged<SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>queryFeaturesStatus <SPAN class="operator token">===</SPAN> Enums<SPAN class="punctuation token">.</SPAN>TaskStatusCompleted<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">"complete"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">let</SPAN> iter <SPAN class="operator token">=</SPAN> queryFeaturesResult<SPAN class="punctuation token">.</SPAN>iterator<SPAN class="punctuation token">;</SPAN> <SPAN class="keyword token">while</SPAN> <SPAN class="punctuation token">(</SPAN>iter<SPAN class="punctuation token">.</SPAN>hasNext<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">{</SPAN> <SPAN class="keyword token">var</SPAN> feat <SPAN class="operator token">=</SPAN> iter<SPAN class="punctuation token">.</SPAN><SPAN class="token function">next</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">;</SPAN> console<SPAN class="punctuation token">.</SPAN><SPAN class="token function">log</SPAN><SPAN class="punctuation token">(</SPAN>JSON<SPAN class="punctuation token">.</SPAN><SPAN class="token function">stringify</SPAN><SPAN class="punctuation token">(</SPAN>feat<SPAN class="punctuation token">.</SPAN>attributes<SPAN class="punctuation token">.</SPAN>attributesJson<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> <SPAN class="punctuation token">}</SPAN> QueryParameters <SPAN class="punctuation token">{</SPAN> id<SPAN class="punctuation token">:</SPAN> params whereClause<SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"1=1"</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></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>
The service in the example you provided the table has an objectid. Ours does not and that may cause problems.
Here is the error.
qml: Suggest like '%2%' and LayerField like 'Parcels-Site_Address'
ArcGIS.AppFramework.Player: Object: QObject(0x0) Text: "file:///C:/Users/huntj/ArcGIS/AppStudio/Apps/6154a8cf097142b38e223b3d9abc999d/MonTopo2.qml:351: TypeError: Cannot read property 'iterator' of null"
file:///C:/Users/huntj/ArcGIS/AppStudio/Apps/6154a8cf097142b38e223b3d9abc999d/MonTopo2.qml:351: TypeError: Cannot read property 'iterator' of null
I got it. I made a typo which caused the error.
Thanks
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.