I'm deploying the Sign Management solutions and just appended 6,000 signs from our existing records to the hosted feature via ArcGIS Pro. There is a Sign ID field that has an Arcade Expression in the ArcGIS Online Form Editor that auto calculates incrementing values on Adding a feature . How do I apply this same code to my appended records to create that Sign ID for them?
var layerIndex = '4'
var idField = 'assetid'
var idPrefix = 'POLE-'
var digits = 6
/*DO NOT CHANGE ANYTHING BELOW THIS LINE
-------------------------------------------------------------------------*/
function GenerateWildcards(digits, wildcard) {
var wildcards = ''
for (var i=0; i < digits; i++) {
wildcards += wildcard
}
return wildcards
}
function GetNextId(layerIndex, idField, idPrefix, padding, sqlFilter) {
// get the feature with the greatest assetid that matches the id pattern specified in the SQL statement.
var assetid_features = Filter(FeatureSetById($datastore, layerIndex, [idField], false), sqlFilter)
var max_assetid_feature = First(OrderBy(assetid_features, `${idField} DESC`))
// If no features match the pattern the featureset will be null, return the first assetid
if(max_assetid_feature == null) {
return `${idPrefix}${Right(padding, Count(padding)-1)}1`
}
// when features do match the pattern calculate and return the next assetid
var max_assetid = max_assetid_feature[idField]
var next_assetid_number = Number(Replace(max_assetid, idPrefix, "")) + 1
return `${idPrefix}${Text(next_assetid_number, padding)}`
}
// Define the edit context so the value is only calculated when the feature is created
if ($editContext.editType == "INSERT") {
// return matching prefix pattern and get next value
var wildcards = GenerateWildcards(digits, '_')
var padding = GenerateWildcards(digits, '0')
if (idPrefix != '') {
var sqlFilter = `${idField} LIKE '${idPrefix}${wildcards}' AND ${idField} NOT LIKE '%[^0-9]'`
GetNextId(layerIndex, idField, idPrefix, padding, sqlFilter)
}
// return number id's only and get next value
else {
var sqlFilter = `${idField} NOT LIKE '%[^0-9.]%'`
GetNextId(idPrefix, padding, sqlFilter)
}
}
else {
return $feature[idField]
}