Quick modification to accomplish that.
var intpoly = FeatureSetByName($datastore, "Polygons_1") // load polygon dataset
var pointvals = FeatureSetByName($datastore,"Dedications",['ID'],false) // load point dataset
var polyname = ''
var polyvals = ''
for( var f in intpoly){ // loop through polys and see which one intersects
if(Intersects($feature, f)){
var polyname = f.TITLE_NAME} // set polyname variable to the TITLE_NAME of intersecting polygon
}
if (!IsEmpty(polyname)){
var polyvals = Filter(pointvals, `TITLE_NAME = '${polyname}'`) // If not empty, filter points by intersecting poly name
}
var numarray = []
for (var n in polyvals){
Push(numarray, n.ID) // push all ID for points with TITLE_NAME matching they polygon name
}
var newID = Max(numarray)+1 // get the max ID number and add 1 to it
return { // return a dictionary that updates TITLE_NAME and ID in the points layer.
"result": {
"attributes": {
"TITLE_NAME": polyname,
"ID": newID
},
}
}
Also, since this gets the values from the ID field from the Dedications point layer by polygon, you will need to have at least one point with the polygon name and an ID >= 0. Otherwise, if you click on 'PolyA', and there is no entry for PolyA in the point file yet, the array of ID's will be empty, so it can't increment it by 1.
Suspect you could also do some error checking here where it appends the TITLE_NAME and if the newID is null, set it to 1, but I normally don't have that many polygons, so I just create one point in each with TITLE_NAME for each polygon, and ID of 0. These 'dummy' points don't really need to fall within the polygons. I normally make them off the side of my map area, and can be deleted once there are ID's for each TITLE_NAME. (Also, no error checking here. This assumes that each point added intersects ONLY 1 polygon (no overlapping polygons)
Hope this makes sense and gets you going in the right direction.
R_