I'm trying to build an ExpB site with a photo on the main page that changes every day.
I have created a feature layer on AGOL containing 31 rows. I have a field for DAY that contains integer values 1-31 for each day of the month. There is one photo stored as an attachment for each day.
In theory, I add an image widget to show attachments. I then set an expression to show the photo where DAY = Today's day.
I have tried for hours to get this work but not sure if it's even possible. Please can someone let me know if I'm flogging a dead horse or if there is indeed a way to make this work. I have tried various Arcade expressions but to no avail. The closest I think I got was using the image URL's but this seems overcomplicated for something that should be relatively easy to achieve. Any ideas or advice would be welcome 🙂
This isn't something I've tried, but it definitely seems possible.
Is the layer available publicly? I'd like to experiment but don't have any data on hand to try. Alternatively, copy and paste the code you're trying and take a screenshot of the image widget configuration.
Hi @NicoleJohnson The feature layer containing the photos is not public. I have a feeling it would be much easier if it was!
I don't have an arcade expression ready yet. I'm not sure yet how to build one in ExpB or if it would be possible in this environment
Ok, I gave this a try but I'm sure it's not the best method that exists. I'm mostly posting this because people love to be right on the internet, so by posting something dumb hopefully both of us can get the actual solution...
This was more complicated than I thought it would be due to needing to use Arcade to filter the data, but then by bringing the data in via Arcade, it seems none of the token stuff happens automatically for the attachments (to make sure you're actually allowed to access this non-public data). I don't know anything about tokens, but I think the token you grab via the directions below might expire eventually (?), so that's something to consider.
To get the token:
// Access photos layer
var p = Portal("https://www.arcgis.com")
var photos = FeatureSetByPortalItem(p, "695a35a53a3b45628c840c48a366ad7c", 0, ['OBJECTID', 'DAY'], false)
// Get today's day of the month
var todaysDay = Day(Today())
// Filter photos layer by day of the month
var filteredPhoto = Filter(photos, "DAY = @todaysDay")
// Set up a dictionary
var newDict = {fields: [
{name: 'Day', alias: 'Day', type: 'esriFieldTypeSmallInteger'},
{name: 'Photo_URL', alias: 'Photo URL', type: 'esriFieldTypeString'}
],
geometryType: '',
features: []
}
// Get the photo
for (var photo in filteredPhoto){
var attach = Attachments(photo)
var Part1 = "https://services8.arcgis.com/IGysY44dU9lNnAZQ/arcgis/rest/services/TestTestTest/FeatureServer/0/"
var ObjectID = photo.OBJECTID
var Part2 = "/attachments/"
var AttachID = First(attach).ID
var Token = "?token=This will be a really long string"
Push(newDict['features'], {attributes: {Day: photo.Day, Photo_URL: Part1 + ObjectID + Part2 + AttachID + Token}})
}
// Create a featureset from the dictionary
var photo_fs = FeatureSet(newDict)
return photo_fs
Are you returning the day number from Today using the Day(<date>) function? Also, this won't randomize your photos, as seems to be what you want in this thread if I'm reading you correctly.
Hi @ZenMasterZeke That's the idea - just match todays day with the day from the feature layer i.e. 1-31. I have also commented on that thread asking for help