Hi all,
I am trying to come up with a code to auto-generate ID code using the calculated field in fieldmap designer/form. The ID should have the format "Alpha Code_Year_Serial Number". The serial number will restart every year. I was able to accomplish this by adding three different fields and combining them in ID with this code:
Concatenate([$feature.AlphaCode, Text($feature.YearID), Text($feature.SerNum)], '_')
However, I really want to make it a single field thing where I can just calculate it within "NestID" only (without the need to create YearID and Serial number field). I have attempted with the code below, I have tested each part individually and I am stuck with the concatenate function doesn't seem to work.
var timestam = Today()
var currentyear = Text(timestam, 'YY')
var currentFeature = $feature["NestID"]
if (IsEmpty(currentFeature)) {
var features = FeatureSetByName($map,'Nest Location', ['NestID','YearID', 'AlphaCode', 'SurveyDate'], true);
var Year = Text($feature["SurveyDate"], 'YY')
var features2024 = Filter(features, 'YearID = @currentyear')
var countOfFeatures = Count(features2024);
if(countOfFeatures == 0) {
return Concatenate([$feature.AlphaCode, Text($feature.YearID), Text($feature.SerNum)], '_')
}
else
{
return Concatenate([$feature.AlphaCode, Text($feature.YearID), Text($feature.SerNum)], '_')
}
}
else
return $feature["NestID"]
When I hit the test, it ran fine showing me a result (first ID that already existed in my database). However, when I tested it in the field map, none of the text would show up after I filled in the survey date and Alpha Code(only showing "__"). I wonder if anyone can find bugs in the code. Thank you in advanced!
Your concatenate is still looking for fields named "AlphaCode", "YearID and "SerNum".
You need to change your concatenate to reference the variables you've cast in your earlier code
Unsure what format you want your serial number to take. You can always pad it with leading zeros, but something like this as a starter for 10?:
Concatenate([$feature.AlphaCode, Year, Text(countOfFeatures)], '_')