Select to view content in your preferred language

How to get the indices of items in an array using Arcade

1446
4
Jump to solution
10-17-2021 06:04 AM
Labels (1)
pat_algura
Occasional Contributor

I have a hosted feature service with Attachments, and I want to create a list of indices of the attachments per feature. Ultimately, I want to get the position of each attachment per feature.

I used Array(Count(Attachments($feature)), which creates an array based on the number of attachment the feature has, but I'm stuck here. I'm new to Arcade and will appreciate any help!

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
JohannesLindner
MVP Frequent Contributor

 

var attachments = Attachments($feature)
var txt = []
for(var a in attachments){
    Push(txt, a+1)
}
return Concatenate(txt, ", ")

 

 

What's your end goal here? Because I fear it's linking those indices to the attachments. If so, you're on the wrong track.


Have a great day!
Johannes

View solution in original post

4 Replies
SzuNyiapTang
Esri Contributor

Hi @pat_algura 

Attachments($feature) will gives you the dictionary of the attachments per feature.

You can then loop through the dictionary to get the id.

var attachments = Attachments($feature)
var txt = ""
for(var attach in attachments){
    txt += (attachments[attach].id) + ","
}
return txt

 

Cheers,

Tang

Cheers,
Tang
0 Kudos
pat_algura
Occasional Contributor

Thanks for responding @SzuNyiapTang 

This approach pulls the attachment ids though instead of indices.

palgura_j_0-1634525502383.png

For each element, I want it to show:

Attachment List
1,2,3,4,5
1,2,3,4
1,2,3,4

 

Thanks,

Patricia

0 Kudos
JohannesLindner
MVP Frequent Contributor

 

var attachments = Attachments($feature)
var txt = []
for(var a in attachments){
    Push(txt, a+1)
}
return Concatenate(txt, ", ")

 

 

What's your end goal here? Because I fear it's linking those indices to the attachments. If so, you're on the wrong track.


Have a great day!
Johannes
pat_algura
Occasional Contributor

Thank you! This is exactly what I'm trying to achieve 😄

palgura_j_1-1634639620023.png

Cheers,

Patricia

0 Kudos