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

237
4
Jump to solution
10-17-2021 06:04 AM
Labels (1)
palgura_j
New Contributor III

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
Regular 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 @palgura_j 

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

0 Kudos
palgura_j
New Contributor III

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
Regular 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

palgura_j
New Contributor III

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

palgura_j_1-1634639620023.png

Cheers,

Patricia

0 Kudos