Is there a way to "lock" in a value that can't be changed in future edits?

516
5
Jump to solution
03-29-2023 04:17 AM
GuyWeerasingheAFF
New Contributor III

Hi there,

Thought I had the incremental numbering working in field maps, until I started revisiting old data points and noticed the groupID changed from the old number to the new group ID in the sequence.

Background - we conduct aerial surveillance of feral animals, making counts of various groups of feral animals seen from the air. Each group is assigned a sequential number that starts from one from each new survey ID (ReviewedSurveyID). Generally, we don't switch survey IDs mid survey, but I've set the code to hopefully factor for that. 

Problem - sequential numbering is working ok, except when I need to revisit the point to make an edit (for example, to provide sample details or update the count of animals seen) - I've noticed that each time I go back to the point to make a minor change or update, the group's ID will be changed. So for example, if I have a group of feral pigs with a count of 5 and a groupID of 40, if I were to make subsequent counts of other feral animals (groupIDs 41-43) and then return to group 40 to take some samples, when I go into group 40's point, it's ID changes from 40 to 44. 

Is there a way to lock in the variable after it has been entered/calculated. Kind of like with Survey123 and the use of once()

I have tried to incorporate the feedback from this post but not having luck with landing this - Solved: arcade calculation - once() or only when null - Esri Community

Here is my Arcade script so far:

If (!IsEmpty($feature.Group_ID)){
  //save a new Inspection Date


//works online and with offline maps, won't work with offline AGOL maps
//increment by 1 from highest number for only features within current year
var Activity_Code = $feature.ReviewedSurveyID
var numberlist = FeatureSetByName($map,"Groups")
var filteredActivity = Filter(numberlist, 'ReviewedSurveyID = @Activity_Code')
var topnum = Top(OrderBy(filteredActivity,'Group_ID DESC'),1)
var counter = Number(Max(topnum,'Group_ID'))
var Groupid = counter+1

return Groupid
//Return topnum
}
 
Currently this script is still changing my GroupID when not null
0 Kudos
1 Solution

Accepted Solutions
DanielMiranda2
Occasional Contributor

We are missing a return statement from your code for when the Group_ID is not blank.

I copied and pasted your code below, with both the removal of the ! and the additional return statement at the end.

I think this should do it.

If (IsEmpty($feature.Group_ID)){
  //save a new Inspection Date


//works online and with offline maps, won't work with offline AGOL maps
//increment by 1 from highest number for only features within current year
var Activity_Code = $feature.ReviewedSurveyID
var numberlist = FeatureSetByName($map,"Groups")
var filteredActivity = Filter(numberlist, 'ReviewedSurveyID = @Activity_Code')
var topnum = Top(OrderBy(filteredActivity,'Group_ID DESC'),1)
var counter = Number(Max(topnum,'Group_ID'))
var Groupid = counter+1

return Groupid
//Return topnum
}
return $feature.Group_ID

 

Note that you can format code to make it easier to read by clicking "expand toolbar," the three dots at the top of the text window here, and then clicking "insert cdde sample." Its icon looks like: </>.

 

 

View solution in original post

5 Replies
DougBrowning
MVP Esteemed Contributor

There are some new vars you can check to see if it is a new feature or not which may help. Something like if brandnewfeature do this.  I cannot find the page right now but look for that.  It was talked about at Dev Summit as its new.  Be aware though that some weirdness when you copy a feature it does not think it is new.  

Hope that helps

0 Kudos
DanielMiranda2
Occasional Contributor

To make sure I understand correctly, your Group_ID is blank for a new record, and will be filled the first time you collect the point? If so, you are on the right track. Drop the ! from your If statement. !IsEmpty evaluates to False if the field is empty, meaning, it will only calculate an ID if there is already one in the field.

 

You want the Group_ID assigned only if the field is blank, otherwise, leave it alone. So it should be:

If(IsEmpty($feature.Group_ID))

This evaluates to True when there is not a Group_ID.

0 Kudos
GuyWeerasingheAFF
New Contributor III

Thanks for that

That is correct - I want blank group IDs to get the new sequential ID and when I fill in the new point, that group ID to be laid down. Any old points need to just retain their old IDs (if we need to revisit the point to add more data)

I made the change and it threw the collection form into a tailspin - I have "Group_ID" for each point collected and it started blinking and prevented me from submitting any data for a new point. Visiting an edited point still changed the old Group_ID designation to the new one (ie. from group_ID 3 to Group_ID 42), and kept on blinking and preventing the form to be submitted. 

0 Kudos
DougBrowning
MVP Esteemed Contributor

I wonder if it is because you are returning a number vs a string?

0 Kudos
DanielMiranda2
Occasional Contributor

We are missing a return statement from your code for when the Group_ID is not blank.

I copied and pasted your code below, with both the removal of the ! and the additional return statement at the end.

I think this should do it.

If (IsEmpty($feature.Group_ID)){
  //save a new Inspection Date


//works online and with offline maps, won't work with offline AGOL maps
//increment by 1 from highest number for only features within current year
var Activity_Code = $feature.ReviewedSurveyID
var numberlist = FeatureSetByName($map,"Groups")
var filteredActivity = Filter(numberlist, 'ReviewedSurveyID = @Activity_Code')
var topnum = Top(OrderBy(filteredActivity,'Group_ID DESC'),1)
var counter = Number(Max(topnum,'Group_ID'))
var Groupid = counter+1

return Groupid
//Return topnum
}
return $feature.Group_ID

 

Note that you can format code to make it easier to read by clicking "expand toolbar," the three dots at the top of the text window here, and then clicking "insert cdde sample." Its icon looks like: </>.