Select to view content in your preferred language

Arcade not working in Pop-Up

1659
12
10-17-2023 07:40 AM
BrianBulla
Honored Contributor

Hi,

The following Arcade expression seems to be working in the Expression builder, but after saving and adding to a pop-up nothing gets displayed.

Any ideas as to what might be going on??

BrianBulla_0-1697553587954.png

 

BrianBulla_1-1697553634313.png

 

0 Kudos
12 Replies
BrianBulla
Honored Contributor

So based on this question (https://community.esri.com/t5/arcgis-online-questions/arcade-expression-correct-but-doesn-t-show-up-...), I have modified my code to return a dictionary instead of a value, but still no luck.  Again it works in the expression builder, but not in the pop-up.

I'm also noticing that I don't even have the option to add "Arcade Expression" in my pop-up.  Is this maybe a problem with our Portal??  @JohannesLindner 

BrianBulla_0-1697562867783.png

 

 

0 Kudos
KenBuja
MVP Esteemed Contributor

What version is your Portal? The Popup element was added in Arcade v1.16, which is available in Portal 11.0. However, you don't need that as the Text element should be able to show your code properly.

Is there a chance you're using another attribute expression in your text element instead of the RelatedExpressions expression?

0 Kudos
BrianBulla
Honored Contributor

Hi Ken,

I have no idea what version our Portal is but it's definitely not the most recent version.  It's managed by our IT department.

As for the expression, I only have the one expression in that Text element.  Whether returning a dictionary or a value, I cannot get it to work in the Pop-Up.

BrianBulla_0-1697565193154.png

 

 

var related = FeatureSetByRelationshipName($feature, "GISWRKS1.WORKS.INSPECTIONS_Valve_Inspection");
var output = `${count(related)} Previous Inspection`;
if (count(related) != 1) output += "s";
for (var rec in related) {
  output += `${TextFormatting.NewLine}• ` + Text(rec.INSP_DATE, 'DD/MM/YYYY')
}
return {
    type: 'text',
    text: output
}

 

 

0 Kudos
KenBuja
MVP Esteemed Contributor

If you're using a Text element, use "return output" instead of returning the dictionary.

When you click the Run button to test the script in the editor, it should use the first record in your table. You can check that by examining the feature's ID in the console (click on Messages after running the script).

console($feature.OBJECTID)

Does the popup work if you click on that first record on your map?

0 Kudos
BrianBulla
Honored Contributor

Yes, using output or a data dictionary the result is the same.

If I find that feature that is showing up when I click the "Test" button in the expression builder, still nothing shows up in the pop-up.  See screenshots below.

I really have no idea what is going on and why this isn't working.

BrianBulla_0-1697567637187.png

BrianBulla_1-1697568030165.png

 

 

0 Kudos
KenBuja
MVP Esteemed Contributor

You can start testing if the script is crashing on a specific line. Uncomment the return statements one by one to see if it makes it to that point.

//return "Start"
var related = FeatureSetByRelationshipName($feature, "GISWRKS1.WORKS.INSPECTIONS_Valve_Inspection");
//return "Relate worked"
var output = `${count(related)} Previous Inspection`;
if (count(related) != 1) output += "s";
//return "Starting loop"
for (var rec in related) {
  output += `${TextFormatting.NewLine}• ${Text(rec.INSP_DATE, 'DD/MM/YYYY')}`
}
return output

 

0 Kudos
BrianBulla
Honored Contributor

Hi Ken,

Thanks for the insight.  While all of the code works in the expression builder, it seems like all of the code in lines 4, 5 and 7 is not working.

If I do this I can get the output to say "Previous Inspection" in the map pop-up, but in the expression builder it always shows me the results I actually want.  Why would it show up differently in the expression builder than in the map?

I am using the same feature in the map that the expression builder is using.

 

var related = FeatureSetByRelationshipName($feature, "GISWRKS1.WORKS.INSPECTIONS_Valve_Inspection");
//return "Relate"

var output = `Previous Inspection`;
//return "var setup"
//if (count(related) != 1) output += "s";
//return "First loop"

for (var rec in related) {
  output += `${TextFormatting.NewLine}• ` + Text(rec.INSP_DATE, 'DD/MM/YYYY')
}
return output

 

 

0 Kudos
BrianBulla
Honored Contributor

And breaking things down a bit further, even if I do this, I cannot get anything to display in the pop-up but it does display in the expression editor.

var related = FeatureSetByRelationshipName($feature, "GISWRKS1.WORKS.INSPECTIONS_Valve_Inspection");
//return "Relate"

var output = count(related) //`Previous Inspection`;
//return "var setup"
//if (count(related) != 1) output += "s";
return output

 

Would there be some reason why the function "Count" might cause it to crash??

0 Kudos
KenBuja
MVP Esteemed Contributor

I've used that to count related records in a popup on AGOL and it works as expected.

0 Kudos