Select to view content in your preferred language

Incremental ID using arcade

636
2
04-07-2024 04:43 AM
GuyWeerasingheAFF
Occasional Contributor

Here's one that I keep coming back to with some success until I rejig it and it then falls apart.

Purpose of this script is to generate a sequential number for a group (when Group_ID is empty). So as we make observations of each feral animal group we see in a day, it will sequentially add a new group ID from 1 onwards. 

For this to work, a temp unique ID is generated that concats the username + day + month+year (temp_unique_activity_code).

Currently the below script generates a group ID of 1, but subsequent groups observed and recorded as Group ID 1 and there is no sequential progression. Based 

Issues I'm noticing include:

1. when checking on filteredActivity, the provided table is blank with only the column headers. Is suspect this is the line where it's all falling apart as the Filter is not functioning, and each group is given "1" due to not having a filtered list to work off. 

This used to work in AGOL (admittedly was using a different reference field), but since moving it to Enterprise I'm just not making any success. I am wondering if this may be due to having the feature class in the geodatabase. Next thing to explore is whether NextSequence Value on Group ID may be the solution. 

Any thoughts?

Guy

 

If (IsEmpty($feature.Group_ID)){
  
//works online and with offline maps, won't work with offline AGOL maps
//increment by 1 from highest number for only features captured on the same date and user, as generated by temp_unique_activity_code

var Activity_Code = $feature.temp_unique_activity_code
var numberlist = FeatureSetByName($map, "Feral Animal Groups")
var filteredActivity = Filter(numberlist, "temp_unique_activity_code = '@Activity_Code'");
var topnum = Top(OrderBy(filteredActivity,'Group_ID DESC'),1)
var counter = Number(Max(topnum,'Group_ID'))
var Groupid = ++counter

return Groupid

}
return $feature.Group_ID

 

2 Replies
BrennanSmith1
Regular Contributor

I don't understand how your data is set up, but I generate incremental numbers for unique points associated with a site using this arcade script:

return Count(Filter($layer,"siteguid  = '" + $feature.siteguid + "'"))+1

 

GuyWeerasingheAFF
Occasional Contributor

@BrennanSmith1 Sorry - yeah we discovered that one of the fields "temp_unique_activity_code" wasn't getting calculated automatically (it too had an arcade script behind it), so we had to plug in the temp_unique_activity_code calculation within the above script to capture it and make use of it. 

0 Kudos