Select to view content in your preferred language

Assistance needed with using the pulldata("@layer") function to retrieve the ID for the most recent submitted record.

479
2
Jump to solution
02-26-2024 01:42 PM
JoseBarrios1
Occasional Contributor III

Hello everyone,

I need to create a note that retrieves the record ID for the last submitted record that matches  a  zone ID. I've attempted to use the pulldata("@layer") function for this purpose, but the sorting statement ORDER BY CreationDate DESC doesn't seem to work as I expected. I've also tried using the objectId and timeStamp fields, but they didn't work either. Here is the expression that is currently working but only pulls the first matching record: pulldata("@layer", "getValue", "attributes.nest_ID", "https://services.arcgis.com/......./FeatureServer/0", concat("nestZoneKey='", ${nestZoneKey}, "'"), "ORDER BY CreationDate DESC", "1")

Thanks for any help or suggestions!

0 Kudos
2 Solutions

Accepted Solutions
abureaux
MVP Regular Contributor

I think your syntax is wrong? If you look at the blog, orderByFields should be added to the URL.

I copied the blow text from the blog:

Refining point-in-polygon queries using extra parameters

On top of the well defined parameters you can pass to the getRecord and getRecordAt operations, you can also pass extra parameters to the feature layer url  to perform some more advanced queries. For example:

  • distance: This parameter allows you to buffer the input geometry (geopoint) to find polygons within a given distance. By default, the distance units come in meters, but you can also specify other units. For example, the following expression will apply a buffer of 1600 feet to the provided location (geopoint) and find any intersecting polygons in the critical habitats layer.

pulldata("@layer", "getRecordAt", "https://services.arcgis.com/QVENGdaPbd4LUkLV/ArcGIS/rest/services/USFWS_Critical_Habitat/FeatureServ...?distance=1600&units=esriSRUnit_Foot", ${location})

I highlighted in blue the key part where the distance and units are specified. These extra parameters are added to the URL. You need to add a question mark (?) to start adding extra parameters and then separate them with an ampersand symbol (&).

  • gdbVersion: This parameter is useful if you want to query a versioned multi-user geodatabase feature layer. 
  • orderByFields: If you expect your query to return more than one value, you can use this parameter to sort the results. For example, say you use getRecord to get all tickets submitted by a user. You can use orderByFields to sort all tickets by date in descending order. This will make your getRecord operation to give you back the latest ticket submitted.
  • outStatistics and groupByFieldsForStatistics: Ideal when you want to retrieve stats from your layer, rather than a unique record or value.  This is how, for example, you will want to get a count of records in a layer.

Check the Query (Feature layer) help topic to learn more about all the extra parameters you can use. The Request Parameters section in this help topic describes the parameters that you cannot use. 

View solution in original post

JoseBarrios1
Occasional Contributor III

Thanks abureaux !

Indeed, you were correct. After a few attempts, I managed to get it working. Here's the final expression in case someone else encounters a similar requirement. Thank you once again for your assistance!

pulldata("@layer","getValue","attributes.nest_ID","https://services.arcgis.com/....._results/FeatureServer/0?orderByFields=survey_Date_time DESC",concat("nest_ZoneKey='", ${nest_ZoneKey}, "'"),"?t=", now())

JB

View solution in original post

2 Replies
abureaux
MVP Regular Contributor

I think your syntax is wrong? If you look at the blog, orderByFields should be added to the URL.

I copied the blow text from the blog:

Refining point-in-polygon queries using extra parameters

On top of the well defined parameters you can pass to the getRecord and getRecordAt operations, you can also pass extra parameters to the feature layer url  to perform some more advanced queries. For example:

  • distance: This parameter allows you to buffer the input geometry (geopoint) to find polygons within a given distance. By default, the distance units come in meters, but you can also specify other units. For example, the following expression will apply a buffer of 1600 feet to the provided location (geopoint) and find any intersecting polygons in the critical habitats layer.

pulldata("@layer", "getRecordAt", "https://services.arcgis.com/QVENGdaPbd4LUkLV/ArcGIS/rest/services/USFWS_Critical_Habitat/FeatureServ...?distance=1600&units=esriSRUnit_Foot", ${location})

I highlighted in blue the key part where the distance and units are specified. These extra parameters are added to the URL. You need to add a question mark (?) to start adding extra parameters and then separate them with an ampersand symbol (&).

  • gdbVersion: This parameter is useful if you want to query a versioned multi-user geodatabase feature layer. 
  • orderByFields: If you expect your query to return more than one value, you can use this parameter to sort the results. For example, say you use getRecord to get all tickets submitted by a user. You can use orderByFields to sort all tickets by date in descending order. This will make your getRecord operation to give you back the latest ticket submitted.
  • outStatistics and groupByFieldsForStatistics: Ideal when you want to retrieve stats from your layer, rather than a unique record or value.  This is how, for example, you will want to get a count of records in a layer.

Check the Query (Feature layer) help topic to learn more about all the extra parameters you can use. The Request Parameters section in this help topic describes the parameters that you cannot use. 

JoseBarrios1
Occasional Contributor III

Thanks abureaux !

Indeed, you were correct. After a few attempts, I managed to get it working. Here's the final expression in case someone else encounters a similar requirement. Thank you once again for your assistance!

pulldata("@layer","getValue","attributes.nest_ID","https://services.arcgis.com/....._results/FeatureServer/0?orderByFields=survey_Date_time DESC",concat("nest_ZoneKey='", ${nest_ZoneKey}, "'"),"?t=", now())

JB