Identify last value entered to generate next value

578
5
04-05-2022 07:09 AM
LouiseHarris1
New Contributor III

I am setting up a form for capture of Phytophthora Ramorum data and the users need to generate Target Site ID. To do this they need to identify the last ID generated to create the next one. How would I set this up and could the ID be auto generated. Can this be set up for use both online and offline?

0 Kudos
5 Replies
ajevans429
New Contributor III

The following code will return the highest ID value present in the feature class, and then add 1. Is this what you're looking for? I think calculated expressions in field maps works online and off.

//access all features in the feature class you are working with (building footprints)
var allFeatures = FeatureSetByName($map,"Building_Footprints",['BUILDINGID'],false)
//identify last feature by highest ID value
var lastFeature = First(Orderby(allFeatures,'BUILDINGID DESC'))
//if features are found, return ID + 1
if (Count(allfeatures) == 0) {
    return ""
} else {
    return lastFeature.BUILDINGID + 1
}

 

0 Kudos
DougBrowning
MVP Esteemed Contributor

Be careful if you have multiple people offline at the same time this will break down.  Even when online if user 1 starts a form and gets a number, then while user 1 is still editing user 2 creates a new form they both get the same id.  In the end I suggest not worrying about sequential numbering.  There are other ways to create ids that are much less trouble and meaningful.  Hope that helps

ajevans429
New Contributor III

@DougBrowning , could you point us to the "other ways" that you are referencing. I've done it in the past using an enterprise setup with attribute rules, but do you have a good solution for AGOL hosted data (other than the one I mentioned)?

0 Kudos
DougBrowning
MVP Esteemed Contributor

For sure not an easy problem.  First why do you need IDs?  Is it for relationships?  Sometimes people are just used to Ids but with spatial data it is not needed as much.  

In one project here we know all the points crews are going to for the field season upfront.  So we load up the points and generate a ID based on a formula - like State_Project_Design_DesignID_VisitNumber. I like this because if a ID is ever wrong or gets messed up we know exactly how to regenerate it.  Plus it has meaning to users. 

A second project we know all the points for a year but they may go to that site more than once so doing the date stamp method.  We have a pregenerated id that then gets the date on the end.  I do this using Arcade in Field Maps at the time of collection.  Concatenate($feature.PointID, "_", text($feature.FieldEvalDate, "Y-MM-DD"))  They create a Field Visit record in Field Maps, the ID generates then it passes to all my 123 forms.  Could do this in 123 also.  This may work for you if you go once per day.  Or if more than one you could add a time in there also.  Like TargetSiteID_04-06-2022.  Or if it is a related table just pass TargetSIteID to it, no need for its own ID.

Third project we have no preset IDs since it is up to each person where they are going to collect data.  This one is harder since it may have more than one geometry per form.  Also they may start with the Geo or the Form first.  If they start with the form I use uuid() in 123 to generate a random id and pass that to Field Maps to relate.  If they start in Field Maps I have them copy globalid into the ID field (this will be attribute rules when they come so clunky for now).  I could also pass the globalid or use Arcade to generate a date based one.  I never use globalid since they cannot be edited and will change when moving to other DBs.  So the IDs are ugly but unique. 

Hope that helps.  No real great way.  But trying to keep perfect 1,2,3 looking IDs right when I have 500-1000 diff tablets all offline is impossible.  You did not specify if it will be just one crew on a site or that part.  If it is all on one tablet then using FeatureSet as posted above could work as long as they have all the older records offline with them, or at least the last one.

LouiseHarris1
New Contributor III

Hi

 

Yes I thought multiple editors and offline working could cause issues. Is it possible that the Target Site ID could be auto populated within AGOL after data has been synced from Field Maps using an arcade expression or some other way?

0 Kudos