Displaying Last Modified Date for Esri REST Service

block with number 8 on top of block with words March

The other week, I was working with some property records data. The data was over a week old. I know this because the data is from my old employer, and I developed an automated process to update the ArcGIS Online-hosted feature service on a weekly basis.

As I considered the failure of this process, an idea came to mind. An enhancement to the property viewer application could displaying the date the property records web service was last updated. The applications is built with Esri’s Web AppBuilder, and there is space on the top of the page, above the map.

screen shot of a web map application
concept of adding a last updated date on web map application

Then, I was reminded about a back-burner idea I had, based upon an Esri Community post I read (can’t find the link). You can access various properties of publicly-shared ArcGIS Online items by accessing the following url, replacing “itemid” with the actual itemid property of the feature service:

https://www.arcgis.com/sharing/rest/content/items/itemid?f=json

There is a property named “modified” that corresponds to the modified date of the item. According to the ArcGIS REST API, this property is the “date the item was last modified. Shown in UNIX time in milliseconds.” So technically, this date may not always represent when the feature service was last modified. But in our example, it is usually the case.

screen shot of json format of arcgis online item details
ArcGIS Online feature service item details in padded JSON format

We can create a function to fetch the item details URL, get the modified property, reformat the date to a human-friendly format, and then place that date in an element on our web map app. Below is a CodePen for my solution.

Below is a walk-through of the “getDateUpdated” function.

  • The function takes two arguments: “url” is the ArcGIS Online feature service item URL that contains the “modified” property of the feature service; “element” is the DOM-element where we will insert the last modified date.
  • The fetch method is called on the url parameter.
  • The json method is called on the response.
  • The data is tested to see if it contains the ‘modified‘ property.
  • If it does not have the ‘modified’ property, we set an error message to our DOM-element, and exit the function. (check this “bad” url for an example)
  • If it does have the ‘modified’ property, we set a variable to contain that property.
  • A helper function is called to reformat the data to the MM-DD-YYYY format. (found on StackOverflow a couple years ago, but can’t find link)
  • Set the DOM-element to the human-friendly date format of the modified date for the feature service.

I’m sure there are ways to improve this solution. If you have any ideas, please share in the comments. My goal was to present an initial idea on how to get the modified date for a feature service, and put that date on the web map application to inform users.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s