Select to view content in your preferred language

Arcade pop ups - Can you return field lists for multiple records?

426
1
Jump to solution
08-12-2024 10:52 AM
LisaMerkhoferXerces
New Contributor

Hi all! I am trying to create a custom pop up in Map Viewer with the Arcade content element that will return related records from another layer (there is no relationship class, I am just using a filter statement). My challenge is that the relationship is 1:M and I would like to have the pop up display data from more than one record as a field list (i.e. return type "fields", as opposed to text or a pop up string). 

Is it possible to return a field list type for more than one record in an arcade element? Here's the basic code I am using that just gets the first related record, how can I modify it to return all related records? Thanks in advance for your ideas!

This code is modified from: https://www.esri.com/arcgis-blog/products/arcgis-online/mapping/part-2-introducing-arcade-pop-up-con... 

//Get count sublayer
var CountTable = FeatureSetByPortalItem(Portal("[url]"),"[itemID]", 0, ['*'],false)

// Filter related features by using a common attribute
Expects($feature, '*');
var siteID = $feature.SiteID
var filterStatement = 'SiteID = @SiteID'

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

//Sort relatedData by date - I'd like to not just use the first record here if possible
var relatedDataSorted = First(OrderBy(relatedData,'ObsDate'))

//Get a list of the fields in the counts table
var countFields = Schema(relatedDataSorted).fields;
//Console("list of fields "+countFields)

//define custom functions
//function to list the name of a field
function getNames(field){
  return field.name;
}
 
//function to collect field metadata info
function getFieldsMetaData() {
  var field_meta = {};
  for (var f in countFields) {
      field_meta[Lower(countFields[f].name)] = {
          "alias": countFields[f].alias,
          "domain":HasKey(countFields[f],"domain"),
          "fieldType": countFields[f].type,
          "name" : countFields[f].name
      }
  }
  return field_meta;
}
 
//applies some basic formatting for dates and domains
function formatField(fieldMetaData) {
    if (fieldMetaData.domain == true) {
        return DomainName(countFields, fieldMetaData.name)
    }
    if (fieldMetaData.fieldType == "esriFieldTypeDate") {
        return Text(countFields[fieldMetaData.name], 'MMM DD YYYY hh:mm')
    }
    return countFields[fieldMetaData.name]
}
 
//function to filter the counts fields to only ones we want to show in the pop up, including no fields with null values.
function filterValidFields(fieldName){
  // skip fields that are not needed, must be listed in lower case
  var skipNames = [
  "objectid",
  "siteid"
  ];
  return !includes(skipNames, lower(fieldName)) //&& !IsEmpty(relatedDataSorted[fieldName]) && !IsNan(relatedDataSorted[fieldName]);
}

//get a filtered list of fields to show in the pop up
var validFields = Filter(Map(countFields, getNames), filterValidFields);

//build the pop up table
var attributes = {};
var fieldInfos = [];
var fieldMetaInfo = getFieldsMetaData();

for (var f in validFields){
  var fieldName = validFields[f];//count fields
  var fieldMeta = fieldMetaInfo[Lower(fieldName)]//lowercase field name
  var fieldAlias = fieldMeta.alias
  Push(fieldInfos, { fieldName: fieldAlias})
  attributes[fieldAlias] = relatedDataSorted[fieldName]
}

return {
  type: "fields",
  fieldInfos: fieldInfos,
  attributes: attributes
};

 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Not easily, no. An Arcade popup element will be limited to a single field list. You can put as many related records into your field list as you want, but they won't be separated in any way, so they'll all sort of bleed together.

The other issue is that your attributes object needs unique keys. As you loop through your related records, you would need a new field name for each record, and while that's doable, it's not going to look great.

Since the text output will honor HTML tags, you could build a table with HTML and assign the appropriate style / class tags to get the final result to render just like a Field List. This would give you the flexibility to do multiple records in a clear way, too.

- Josh Carlson
Kendall County GIS

View solution in original post

1 Reply
jcarlson
MVP Esteemed Contributor

Not easily, no. An Arcade popup element will be limited to a single field list. You can put as many related records into your field list as you want, but they won't be separated in any way, so they'll all sort of bleed together.

The other issue is that your attributes object needs unique keys. As you loop through your related records, you would need a new field name for each record, and while that's doable, it's not going to look great.

Since the text output will honor HTML tags, you could build a table with HTML and assign the appropriate style / class tags to get the final result to render just like a Field List. This would give you the flexibility to do multiple records in a clear way, too.

- Josh Carlson
Kendall County GIS