Consistent Repeat Indexes when Records Deleted

377
4
07-11-2021 10:30 PM
DarraghOSullivan
New Contributor III

Hi there,

My survey has repeats that record issues identified on walking trails. Our reporting requires each one having a unique Issue ID. I am trying to use the Position(..) function to consistently generate this ID. It works fine unless a record is deleted, which can happen in the field if an inspector realizes an error or the issue is repaired before the inspection is completed. If there are 4 repeats and the first one is deleted, then the next added repeat will mean duplicate IDs. The new one will now be the 4th repeat, so will generate the same ID as the previous record (which was the 4th when generated). 

I've tried using once(), max() - outside the repeat - and a few other things but cannot find a consistent way of doing this. Any ideas? Thanks...

0 Kudos
4 Replies
JamesTedrick
Esri Esteemed Contributor

Hi @DarraghOSullivan ,

If your lifecycle involves deleting a repeat (instead of noting completion on the record), then position(..) would not be suitable for use in generating the ID.  You may be able to create a unique id via a custom JavaScript function that increments (i.e., adds 1 to the previous ID number).  Alternatively, you could use an ID number that is not based on an incrementing number (derived by location, timestamp or other attribute that uniquely identifies the record).

DarraghOSullivan
New Contributor III

Thanks @JamesTedrick. I thought there might be something simple I was missing! It's rare that a repeat would be deleted so I think it's worth persisting and changing IDs in the Feature Service on the rare occasion it's needed.

0 Kudos
DougBrowning
MVP Notable Contributor

I use position a lot now but normally we do not delete.  It could explain a few weird data records I have seen though.

I spent time doing a lot of testing on this yesterday and I cannot come up with anything that works.  It is esp hard if they delete more than 1 at a time.

I did get some javascript working that grabs the last value.  In the end I did not use it since my repeat is so large that it is causing memory issues.

call in the field
calculation line
pulldata("@javascript", "functions.js", "sameaslast", ${LPIDetail}, number(${RecCount}), "TopCanopy")

actaul function

function sameaslast(repeat, position, fieldname) {
	if (position > 1){
		return repeat[position - 2][fieldname];

	}
}

You could write some arcade in the popup that would tell you if there are any dups.  Here is a sample I did for a diff project.  I actually use this in Ops Dashboard to show me any dups.

var p = 'https://arcgis.com/'; 
var tbl = FeatureSetByPortalItem(Portal(p),'d12b26608e1842809af6da09',9,['UnknownCode'], geometry = false);
var dups = []
var Dict = {  
 'fields': [{ 'name': 'dups', 'type': 'esriFieldTypeString' }],  
 'geometryType': '',   
 'features': []};  
var index = 0
var last = ''
for (var f in OrderBy(tbl, "UnknownCode")) {
    if (f.UnknownCode == last) {
        Dict.features[index] = {   
            'attributes': {   
                'dups': last,
            }}   
        ++index
        
    }
    last = f.UnknownCode
}
return FeatureSet(Text(Dict));

 

Watching is anyone has other ideas.  Hope it helps

0 Kudos
DarraghOSullivan
New Contributor III

Thanks @DougBrowning 

I was using Count() and it was throwing up strange IDs, especially if an inspector edited a record after initial submission. Position() isn't perfect but a lot better. I was trying to figure out a way to keep a running total of records created outside of the repeat, that could then be referenced for the ID, but got stuck. It might work but just can't quite get there...

Like your case though, it's not common for repeats to be deleted, so I'll just keep an eye on it and try to catch any duplicates. I like the idea of catching them with Arcade, appreciate the code. 

Let's see if anyone else has ideas... 

0 Kudos