Arcade Filter/Relate not working in Popup

770
3
Jump to solution
10-21-2020 02:22 PM
ShawnLanning
New Contributor II

Popup only shows the expression label and then no value even though the arcade expression works in the test expression window.  I followed the blog about using featuresets to create a relate and add it to a popup - https://community.esri.com/community/gis/web-gis/arcgisonline/blog/2020/06/09/show-related-data-or-t... - Gee Fernando's Blog

Here is my code: 

// Write a script to return a value to show in the pop-up.

var portal = Portal("https://services.wygisc.org/portal")
var speciesRelate = FeatureSetByPortalItem(portal,
"6a0c8bcd1d164d99b76f162f140212f8", 0, ['Species', 'Taxa',
'Occurrence_Potential', 'BLM_Status',
'Texas_________________Status', 'Federal_Status', 'Habitat',
'Code'])

// Filter related features by using a common attribute
var HabCode = $feature.HabCode
var codeStatement = 'Code = @HabCode'

//Related features as a variable
var relateData = Filter(speciesRelate, codeStatement)

//build popupString by iterating through all related features
var popupString = ''
for (var f in relateData){

 

popupString += "Species: " + Text(f.Species) + TextFormatting.NewLine +

 

"Taxa: " + f.Taxa + TextFormatting.NewLine +

 

"Occurrence Potential: " + f.Occurrence_Potential + TextFormatting.NewLine +
TextFormatting.NewLine 
}

 

Thoughts?

 

Thanks,

Shawn

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Hi sgl55 ,

Not sure if you did not include the complete expression, but at the end you should return the "popupString". That is the main reason you are not getting any result.

// Write a script to return a value to show in the pop-up.
var portal = Portal("https://services.wygisc.org/portal");
var speciesRelate = FeatureSetByPortalItem(portal,
"6a0c8bcd1d164d99b76f162f140212f8", 0, ['Species', 'Taxa',
'Occurrence_Potential', 'BLM_Status',
'Texas_________________Status', 'Federal_Status', 'Habitat',
'Code']);

// Filter related features by using a common attribute
var HabCode = $feature.HabCode;
var codeStatement = 'Code = @HabCode';

//Related features as a variable
var relateData = Filter(speciesRelate, codeStatement);

//build popupString by iterating through all related features
var popupString = '';
for (var f in relateData){
    popupString += "Species: " + Text(f.Species) + 
                   TextFormatting.NewLine +
                   "Taxa: " + f.Taxa + TextFormatting.NewLine +
                   "Occurrence Potential: " + f["Occurrence_Potential"] + 
                   TextFormatting.NewLine + TextFormatting.NewLine;
}

return popupString;

I would also recommend to access fields that contain an underscore using feature["Field_Name"] and nor as feature.Field_Name (see line 22).

Avoid on lines 4 to 6 to include fields that you are not using to increment performance.

View solution in original post

3 Replies
KenBuja
MVP Honored Contributor

How are you linking the script to the popup? Do you have it checked in the Configure Attributes dialog?

0 Kudos
ShawnLanning
New Contributor II

Yes - I believe I have the pop-up configured correctly and even created a very simple arcade expression that does work, though I could be missing something?  See below:

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi sgl55 ,

Not sure if you did not include the complete expression, but at the end you should return the "popupString". That is the main reason you are not getting any result.

// Write a script to return a value to show in the pop-up.
var portal = Portal("https://services.wygisc.org/portal");
var speciesRelate = FeatureSetByPortalItem(portal,
"6a0c8bcd1d164d99b76f162f140212f8", 0, ['Species', 'Taxa',
'Occurrence_Potential', 'BLM_Status',
'Texas_________________Status', 'Federal_Status', 'Habitat',
'Code']);

// Filter related features by using a common attribute
var HabCode = $feature.HabCode;
var codeStatement = 'Code = @HabCode';

//Related features as a variable
var relateData = Filter(speciesRelate, codeStatement);

//build popupString by iterating through all related features
var popupString = '';
for (var f in relateData){
    popupString += "Species: " + Text(f.Species) + 
                   TextFormatting.NewLine +
                   "Taxa: " + f.Taxa + TextFormatting.NewLine +
                   "Occurrence Potential: " + f["Occurrence_Potential"] + 
                   TextFormatting.NewLine + TextFormatting.NewLine;
}

return popupString;

I would also recommend to access fields that contain an underscore using feature["Field_Name"] and nor as feature.Field_Name (see line 22).

Avoid on lines 4 to 6 to include fields that you are not using to increment performance.