Hi,
I've got a smart form that autopopulates tree numbers for points. It queries the featureset for other tree points with the same project number (or no project number), sorts the values, and then adds 1 to the largest one.
In the map viewer, when I add a new point, it correctly calculates the tree number based on the project number field, and if I update the project number, it recalculates the tree number as expected.


In the Field Maps mobile app, on the other hand, the form does not recalculate the Tree Number field when I update the Project Number field. In fact, it calculates the Tree Number field based on a null Project Number value since that's what was present when the form was opened. Entering or changing the Project Number value has no effect on the Tree Number field.
Our script works fine when we calculate the project number field (we often set up separate maps with the project number automatically calculated for individual projects to save time in the field), but we also want to have a more flexible map & form that can be used to collect data across multiple projects, so field staff will enter the project number manually (side note: I really wish I could opt to cache the value they enter in that field for them like I can in the Survey123 web designer so they only have to enter it once and don't enter the project number inconsistently!).
Does anyone know why it's behaving differently in the mobile app than it is in the map viewer?
Here's my code for reference (I have likely overcomplicated it trying to resolve this issue):
var nextTreeNumber = 1
// If this feature already has a Tree Number, return that
if(!IsEmpty($feature.TreeNumber)) {
return $feature.TreeNumber
}
// Get the project number
var projectNumber = trim(upper($feature.ProjectNum))
// Otherwise, get tree number values for the whole Arborist Template featureset
// Check that the featureset isn't empty
if (!IsEmpty(first($featureset))) {
// Query the featureset for trees with the same project number (even if it's null)
if (isEmpty(projectNumber)) {
var projectTrees = filter($featureset, "ProjectNum IS NULL")
} else {
var projectTrees = filter($featureset, "ProjectNum = @projectNumber")
}
if (!IsEmpty(first(projectTrees))) {
var maxTreeFeature = First(OrderBy(projectTrees, "TreeNumber DESC"))
// if there are no trees with the same project number, return 1
if (isEmpty(maxTreeFeature.TreeNumber)) { return nextTreeNumber }
// if there are trees with the same project number, add 1 to the highest one
var maxTreeNumber = maxTreeFeature.TreeNumber
nextTreeNumber = maxTreeNumber + 1
return nextTreeNumber
} else { return nextTreeNumber }
} else { return nextTreeNumber }
Thanks!
Holly