Arcade expression only running first time in multi-feature popups (Arcade persistence question)

319
0
01-31-2022 01:43 PM
Labels (2)
Jason_Ho
New Contributor II

I've written some Arcade code for popups to pull data from related tables (see below). The popups work fine when there are individual features. The code also runs successfully when there is a stack of features in a popup, but only the first time that the user clicks through the features. After that, the Arcade code is no longer displayed (see images below, the error happens when using the arrow buttons in the upper right). Am I missing something in my code or settings that will make the code persist in the popups or at least run more than the initial time? 

Popup after the first clicking a stack of features and then clicking the next arrow:

Jason_Ho_0-1643663715636.png Jason_Ho_1-1643663753369.png 

The same popup after using the arrows to go back to features that were previously viewed:

Jason_Ho_2-1643663783223.pngJason_Ho_3-1643663821421.png

 

When the popup is closed and the stack of features is clicked again, then the Arcade expression that is pulling the data from the related tables will work the first time but then the error show above is reproduced.

 

My thoughts on possible reasons:

  1. My code is bad (most likely, it's been years since I have done any significant programming).
  2. I am missing a chunk of code that allows related data to persist through users cycling through the features. 
  3. There is a setting that allows allows persistence (or to run the Arcade each time a user cycles) and I missed it.
  4. There is a bug in running the Arcade for popups when cycling through stacked features.

 

Here is a link to a demo with the issue. Click on the northern red triangle to see the issue. The issue is also occurring in the Map Viewer.

Any thoughts or suggestions would be helpful.

Here is the code for the Events (similar code is used for the other 2 layers):

 

 

/* PULLING DATA FROM PHOTOS TABLE 
FOR EVENTS LAYER */
var photos = FeatureSetByRelationshipName($feature,"photos", ['DATE', 'TIME', 'PHOTOURL', 'PHOTOTHMB', 'EVENTID']);
// Filter related features w/ common attribute
var EVENTID = $feature.EVENTID;
var sql = 'EVENTID = @EVENTID';
var eventphotos = Filter(photos, sql);
//return eventphotos;
var sortedphotos = OrderBy(eventphotos, 'EVENTID ASC');
//return sortedphotos;

var photooutput = '<p>Testing output of data from related tables:</p><table style="border: 1px #000000 solid; border-collapse: collapse; width: 100%">';
var row = 1;
for (var i in sortedphotos) {
    var rowcolor = '';
    if ((row % 2) == 0) {
        rowcolor = '#efefef';
    }
    else {
        rowcolor = '#ffffff';
    }
    row++;
    var longdate = Text(i.DATE, 'MMMM D, Y')
    // NEED QUALIFIER CODE
    // IF PHOTOVIS == 1 && PHOTOSTATUS == 1
    photooutput += '<tr style="background:' + rowcolor + 
        '"><td style="padding: 5px; border: 1px #000000 solid; width: 25%;">' +
        longdate + ' ' + i.TIME +
        '</td><td style="padding: 5px; border: 1px #000000 solid; width: 75%;"><a href="' +
        i.PHOTOURL + '" target="_blank"><img src="' + 
        i.PHOTOTHMB + '" alt="' + longdate + ' ' + i.TIME + '">'
        '</td></tr>' +
        TextFormatting.NewLine; 
}

photooutput += '</table>';

return { 
    type : 'text', 
    text : photooutput
}

 

0 Replies