Add related field to ArcGIS Online Popup using Arcade

1973
6
Jump to solution
05-25-2021 02:06 AM
by Anonymous User
Not applicable

Hello:

I want to relate a table hosted on a private ArcGIS Server to a feature layer hosted on the same server using a field called "OIDStr" in the table and a field caled "OIDstr" in the feature layer. I then want to show a hyperlink field in that related table in the popup I configured for the feature layer. What I have so far which I found at this link is not working. Are there any suggestions that could help me? I also may need to incorporate an if statement found here to prevent getting errors when there is no related data.

 

var planrecs = FeatureSetByName($map,"House_Number_Change - Address Form and Plan Recs");
var FullAddress = $feature.FullAddress
var filterStatement = 'OIDStr = @OIDstr'

// Related features as a variable
var relatedData = Filter(planrecs, filterStatement)

// Build the pop-up string by iterating through all related features
var popupString = ''
for (var f in relatedData){

popupString += Text(f.AIN, 'no data') + TextFormatting.NewLine +

"Path: " +
DefaultValue(f.Path, 'no data') + TextFormatting.NewLine

}

DefaultValue(popupString, 'No other records to show')

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

Hi Johannes:

I was able to get it to work utilizing the code @XanderBakker provided at this link: https://community.esri.com/t5/developers-questions/get-1-m-related-objects-using-arcade/td-p/736778 

The related field I want to display multiple related records for in the popup are hyperlinks. They show as text using the solution I used so I tweaked it to only show one hyperlink rather than all. How can I adjust it so are related hyperlinks are shown?

View solution in original post

0 Kudos
6 Replies
JohannesLindner
MVP Frequent Contributor

What exactly is not working? Do you get error messages?

 

var planrecs = FeatureSetByName($map,"House_Number_Change - Address Form and Plan Recs")
var FullAddress = $feature.FullAddress

// var filterStatement = 'OIDStr = @OIDstr'
// this won't work, as you haven't declared the variable "OIDstr". The @ syntax takes care of the proper formatting depending on the type of OIDstr (integer, string, etc), but you have to define what OIDstr actually is:
// also, check the spelling: OIDStr vs. OIDstr
var OIDstr = $feature.OIDstr
var filterStatement = 'OIDStr = @OIDstr'

// Related features as a variable
var relatedData = Filter(planrecs, filterStatement)

// Just exit here if there are no related features
if(Count(relatedFeatures) == 0) {
  return 'No other records to show'
}

// Build the pop-up string by iterating through all related features
var popupString = ''
for (var f in relatedData){
//  popupString += Text(f.AIN, 'no data') + TextFormatting.NewLine + "Path: " + DefaultValue(f.Path, 'no data') + TextFormatting.NewLine
// You're using wrong arguments for Text. I think you want to use DefaultValue?
  popupString += DefaultValue(f.AIN, 'no data') + TextFormatting.NewLine + "Path: " + DefaultValue(f.Path, 'no data') + TextFormatting.NewLine
}
return popupString

 


Have a great day!
Johannes
by Anonymous User
Not applicable

Hi Johannes:

I appreciate your help and for the script. I assume if(Count(relatedFeatures)) was supposed to be if(Count(relatedData)) correct? I am getting the same error message which was 

BrandonPrice2_0-1621975863899.png

I think it still has to do with the issue at this link because the error message I am getting is the same.

0 Kudos
by Anonymous User
Not applicable

The code works when I add it to the table although not the layer. This is because the relationship is one to many I think. Many related records per feature.

 

BrandonPrice2_0-1621979733073.png

 

0 Kudos
by Anonymous User
Not applicable

Hi Johannes:

I was able to get it to work utilizing the code @XanderBakker provided at this link: https://community.esri.com/t5/developers-questions/get-1-m-related-objects-using-arcade/td-p/736778 

The related field I want to display multiple related records for in the popup are hyperlinks. They show as text using the solution I used so I tweaked it to only show one hyperlink rather than all. How can I adjust it so are related hyperlinks are shown?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi @Anonymous User ,

I hate to be the carrier of bad news, but in ArcGIS Online at this moment you cannot return HTML and you will need HTML to create multiple links from a single Arcade expression (ArcGIS Pro supports this, but AGOL is not there yet). There are ways to accomplish this in AGOL (in theory) but these would need multiple expressions and conditional visualization and would have a serious impact on performance.

0 Kudos
by Anonymous User
Not applicable

I will work around this and return the first related hyperlink in the loop in the first expression and the second related hyperlink in the second expression.