Select to view content in your preferred language

[Arcade] How to retrieve all values which has a common ID in another collumn ?

481
17
Jump to solution
a month ago
JasonBOCQUET
Occasional Contributor III

Hi,

I'm working sometimes on Arcade and i'm blocked by a point :

 

I have a table with some teams of people. Each people have a manager (the ID is MANAG001, MANAG002...).

Each people is represented by a point on a map. 

 

I want by clicking on one of the people be able to see on the pop-up box all of the other people who have the same manager that the guy who I clicking on. 

If I click on me, i'm able to see my manager is MANAG004 and i can see the other people who are managed by MANAG004 on a list or a table in the popup.

 

How can I do that with Arcade expression ? 

I've read that Arcade does not support direct interaction with the clicked point’s ID; so maybe i can"t do that ?

 

thx 🙂

0 Kudos
3 Solutions

Accepted Solutions
jcarlson
MVP Esteemed Contributor

No direct interaction, that's true, but pulling the values into a list and displaying the text is fine.

 

var fs = FeatureSetByName($map, 'people table', ['name', 'manager_id'], false)

// filter features for matching manager id
var filt_fs = Filter(fs, `manager_id = '${$feature['manager_id']}'`)

// loop through matches, create list
var match_arr = []
for (var f in filt_fs) {
  Push(match_arr, f['name'])
}

return Concatenate(match_arr, '\n')

 

 This will spit out a list of names, each on their own line of text. Swap in your table / field names as needed, see how it works for you.

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
jcarlson
MVP Esteemed Contributor

Put "Concatenate(match_arr, '\n')" in the text object at the end. You're putting the entire array into your HTML object, you don't really need to do that.

return {
type: 'text',
text: Concatenate(match_arr, '\n')
}

You could also try replacing \n with <br>.

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
jcarlson
MVP Esteemed Contributor

Change your expression to use FeatureSetByPortalItem instead, that will go around the filter.

var fs = FeatureSetByPortalItem(
Portal('your portal url'),
'itemID of the layer',
0, // or whatever the layer index is
['ets_siren', 'ets_date_creation'],
false
)
- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
17 Replies
jcarlson
MVP Esteemed Contributor

No direct interaction, that's true, but pulling the values into a list and displaying the text is fine.

 

var fs = FeatureSetByName($map, 'people table', ['name', 'manager_id'], false)

// filter features for matching manager id
var filt_fs = Filter(fs, `manager_id = '${$feature['manager_id']}'`)

// loop through matches, create list
var match_arr = []
for (var f in filt_fs) {
  Push(match_arr, f['name'])
}

return Concatenate(match_arr, '\n')

 

 This will spit out a list of names, each on their own line of text. Swap in your table / field names as needed, see how it works for you.

- Josh Carlson
Kendall County GIS
0 Kudos
JasonBOCQUET
Occasional Contributor III

Maybe i miss something because it's not working already.

 

It seems to miss a ")" in your line 4 and i don't understand on the line 4 what does mean "

Filter(fs, `manager_id = '${$feature['manager_id']}'`

 why there is duble ${$ ?

0 Kudos
jcarlson
MVP Esteemed Contributor

Ah, you're right, there should be a closing parenthesis on that line. I'll edit the original post.

The filter statement is using a template literal, a kind of text string where you can insert values into it using ${…}. Anything inside the brackets evaluates as code, and is included in the output text. This expression, for instance:

var x = 'cool'

return `Arcade Expressions are ${Upper(x)}`

Would spit out the  text "Arcade Expressions are COOL".

There's a second "$" because that's how we tell Arcade to get the current $feature to access its attributes.

- Josh Carlson
Kendall County GIS
0 Kudos
JasonBOCQUET
Occasional Contributor III

Ok so I try with my data :

 

 

 

var fs = FeatureSetByName($map, "Effectifs Société", ['$feature.ets_date_creation', '$feature.siren'], false)
var filt_fs = Filter(fs, `$feature.siren = '${$feature['$feature.siren']}'`)

var match_arr = []
for (var f in filt_fs) {
  Push(match_arr, f['$feature.ets_date_creation'])
}
return Concatenate(match_arr, '\n')

 

 
but it return nothing again. 
0 Kudos
jcarlson
MVP Esteemed Contributor

The expression in Filter is a SQL statement. The stuff in the ${…} is different because it's evaluated by Arcade first, but the rest of it has to be SQL, where there's no "$feature" object.

`$siren = '${$feature['siren']}'`

Also, you just need the field name in the square brackets. Otherwise, it's going to be looking for a field literally called "$feature.siren" instead of "siren".

- Josh Carlson
Kendall County GIS
0 Kudos
JasonBOCQUET
Occasional Contributor III

Ok, i change all of the content in square brackets :

 

 

var fs = FeatureSetByName($map, "Effectifs Société", ['ets_date_creation', 'siren'], false)
var filt_fs = Filter(fs, `siren = '${$feature['siren']}'`)

var match_arr = []
for (var f in filt_fs) {
  Push(match_arr, f['ets_date_creation'])
}
return Concatenate(match_arr, '\n')

 

 

but it doesn't seems to change anything because my popup box still empty 

 

 

0 Kudos
jcarlson
MVP Esteemed Contributor

After the second line, try adding return Count(filt_fs), what does it show you?

Is the siren field text, or numeric?

- Josh Carlson
Kendall County GIS
0 Kudos
JasonBOCQUET
Occasional Contributor III

Ok I miss something, my field is "ets_siren" not "siren" i'm stupid ^^'

So when I execute it seems to work; but i can't reach to show the result on my popup. Why I can't ?

 

0 Kudos
JasonBOCQUET
Occasional Contributor III

@jcarlson i find how can i see the results, but it seems to show me only one result. He do not reach to have the others line with the same ID's

 

var fs = FeatureSetByName($map, "Effectifs Société", ['ets_date_creation', 'ets_siren'], false)
var filt_fs = Filter(fs, `ets_siren = '${$feature['ets_siren']}'`)

var match_arr = []
for (var f in filt_fs) {
  Push(match_arr, f['ets_date_creation'])
}
Concatenate(match_arr, '\n')
var HTML = ""
HTML += "<p style='text-align: center; line-height: 0.1;'><strong><span style='font-size: 30px; font-family: Calibri, sans-serif; color: rgb(1, 42, 132);'>"+match_arr+"</span></strong></p>"


return { 
	type : 'text', 
	text : HTML
}

sometime i got 2 times the name of the people concerned by the popup, but i never seen the other people appears. 

0 Kudos