How to populate a Dashboard list item that uses an…


You won’t be able to do it without getting into a Data Expression. The Advanced Formatting profile in Arcade can’t see beyond the individual datapoint, so there’s no way to grab attributes from another place.

var fs = FeatureSetByPortalItem(
  Portal('your portal url'),
  'itemid of service',
  0, // or other layer index
  ['ID_num', 'Title', 'Related_nums', 'Pdf_link'],
  false
)

// get the links as own dict in ID:Link format
var link_dict = {}
for (var f in fs) {
  link_dict[f['ID_num']] = f['Pdf_link']
}

// output dict taking incoming schema plus a new field for links
var out_dict = {
  fields: Splice(Schema(fs)['fields'], {name:'rel_links', type: 'esriFieldTypeString'}),
  geometryType: '',
  features: []
)

// loop through featureset
for (var f in fs) {
  
// get array of related numbers
  var rel_num = Split(f['Related_nums'], ', ')

  // loop through and build related link dict
  var rel_link_dict = []
  for (var n in rel_num) {
    rel_link_dict[`link ${rel_num[n]}`] = link_dict[rel_num[n]]
  }

  // push attributes into out dict
  Push(
    out_dict['features'],
    { attributes: {
      ID_num: f['ID_num'],
      Title: f['Title'],
      Related_nums: f['Related_nums'],
      Pdf_link: f['Pdf_link'],
      rel_links: Text(rel_link_dict)
    }}
  )
}

return FeatureSet(Text(out_dict))

 

There is admittedly a lot going on here, and I don’t have similar data handy for testing, but I’ll explain some key points.

While we could just spit out the links as a single text field, you’ll run into a problem when you try to turn those into links. No matter what, you will need to use Advanced Formatting to turn the rel_links field into legitimate HTML in your list item.

Even if we had a list of “link 1, link 2” and used split to break it apart, how would we know which link was which anymore?

By loading the entire dict into a text field, you’ll end up with a big string, something like:

{"link 1": "link from feature 1", "link 4": "link from feature 4"}

 And we can pass that into FromJSON in the Advanced Formatting section to work with it as a dict again. It’s a great way of passing variable-length lists of features / attributes from a Data Expression into the Advanced Formatting section. In your advanced formatting expression, you could try something like this:

var rel_links = FromJSON($datapoint['rel_links'])

var link_arr = []

for (var l in rel_links) {
  Push(
    link_arr,
    `<a href="https://community.esri.com/t5/arcgis-dashboards-questions/how-to-populate-a-dashboard-list-item-that-uses-an/td-p/1513847/jump-to/${rel_link[l]}">${l}</a>`
  )
}

var link_text = Concatenate(link_arr, '<br>')

return {
  attributes: {
    link_text
  }
}

 

Maybe that’s more complicated than you were hoping for. 😬

But I do think it could work!

– Josh Carlson
Kendall County GIS



Source link

Leave a Comment