How to move related feature to a new parent feature in Field Maps and update globalid upon relocation

315
8
04-19-2024 04:01 PM
Teresa_Blader
Occasional Contributor III

I deployed the Signs Inventory ArcGIS Solution. One scenario coming up: moving a sign from one pole on one side of the street to a different pole on the other side of the street without retiring/creating a new sign id. I store the Pole ID and the Pole GlobalID in the Signs layer. The globalids are the keys between Signs and Poles.

I want Pole ID and the Pole GlobalID to update when I move a sign to a new post in Field Maps/Smart Form online. It currently does not.

The related records on Signs (Sign Maintenance table) also fetches Signs: sign ID, pole ID, sign global ID, pole global ID, and latitude/longitude each time a record is added - to retain the move history over the years (hypothetically).

How might I write Arcade to overwrite the pole's globalID in Signs layer with it's new related pole globalID?

My first thought was doing a "buffer/nearest" pole calculated expression, but it seems once the pole globalid field is populated in Signs upon creation - it is not editable and the calculated expression is ignored.

"Editing is disabled in the field settings". Is this a setting I can modify in the REST API or JSON using ArcGIS Assistant?

Teresa_Blader_2-1713566203683.png

Teresa_Blader_0-1713565902094.png

Teresa_Blader_1-1713565922620.png

Expression to fetch Pole ID (assetid) into Signs layer for assetID_pole

var poles = FeatureSetByRelationshipName($feature, 'Poles',['assetid'],true)
// Get the feature set for the poles

// Get the first poles (should only be one)
var pole = First(poles)

// If there was a pole, return the assetid of it,
// Otherwise, return null
if (!IsEmpty(pole)) {
    return pole['assetid']
} else {
    return null
}

 

At some point I tried implementing a calculated expression in the form (like what I did for location description below, getting the nearest county road). For that it was told to fetch the nearest pole globalid within a 10 ft buffer of the sign, but didn't do anything so I removed it. 

// If feature doesn't have geometry return null
if (IsEmpty(Geometry($feature))) { return null }

// Get the roads layer
var agol = 'https://www.arcgis.com/'
var roads = FeatureSetByPortalItem(Portal(agol), '7abbff41fefe4bfa88cec88256022c33',2,['RD_SYMBOL','RD_SYSTEM'],true)
var CR_CSAH = "RD_SYMBOL IS NOT NULL AND (RD_SYSTEM ='CR' OR RD_SYSTEM = 'CSAH')"
var rel_roads = Filter(roads, CR_CSAH)

// Buffer the current location and intersect with roads
var bufferedLocation = Buffer($feature, 200, 'feet')
var candidateroads = Intersects(rel_roads, bufferedLocation)

// Calculate the distance between the road and the current location
// Store the feature and distance as a dictionary and push it into an array
var featuresWithDistances = []
for (var f in candidateroads) {
    Push(featuresWithDistances, 
        {
            'distance': Distance($feature, f, 'feet'),
            'feature': f
        }
    )
}

// Sort the candidate roads by distance using a custom function
function sortByDistance(a, b) {
    return a['distance'] - b['distance']
}
var sorted = Sort(featuresWithDistances, sortByDistance)

// Get the closest feature
var closestFeatureWithDistance = First(sorted)

// If there was no feature, return null
if (IsEmpty(closestFeatureWithDistance)) { return null }

// Return the address */
return `${closestFeatureWithDistance['feature']['RD_SYSTEM']} ${closestFeatureWithDistance['feature']['RD_SYMBOL']}`

 

Teresa Blader
Olmsted County GIS Specialist
0 Kudos
8 Replies
DougBrowning
MVP Esteemed Contributor

Is the field of type globalid?  If so i do not think you can set them.  Can you make it a text field?

Also I see you do a first then test for empty but that will fail so test if poles is empty instead.

var pole = First(poles)

Not sure if that is your issue though.

0 Kudos
Teresa_Blader
Occasional Contributor III

The “poles globalid” field in the signs layer is a guid type - these two are the keys in the relationship.

I’m not using the second script right now. the scripts I copied/modified from the esri blog for common expressions used in field maps. It is the example of where I’d like to go with it - populate the guid field with the global id of the nearest pole for a manual reassignment. However, while I can add the expression like this to the “pole globalid guid field” in signs, it does nothing because there’s no way to enable editing on this field in Field Maps/smart forms. There’s some secret setting somewhere that disables further expressions when it concerns the key field of adding a related record - it does populate the “pole globalid guid field” of course when adding a new sign to an existing pole by clicking “add record” - as designed. 

Settings in field maps on this guid field specifically says “editing is disabled by field settings” and the editing “add expression” gear button is grayed out too - like the picture shows.

So my question is how do I interact with this default field setting to enable editing? Obviously the “add record” button in the form is designed to push the key to the new record, but how could I accomplish this goal of reassigning a sign to a new pole in field maps?

Teresa Blader
Olmsted County GIS Specialist
0 Kudos
DougBrowning
MVP Esteemed Contributor

Change to a text field and it should let you calculate.  All my relates are text fields.  Worth a shot.

0 Kudos
Teresa_Blader
Occasional Contributor III

I didn’t know relationship key fields could be text - thought they had to guids. You’re saying you’ve accomplished this task of overwriting a relationship key field using expressions in your own workflows by just using a text type for the key?

im not sure this sort of swap is really feasible for this project… I’ve got 12,000 records in a hosted feature layer with 11,000 related records plus 19,000 maintenance records, with 1,000 form templates in field maps with a fully operational workflow. I’m not sure how I’d even transition the relationship class to using new field type. Overwriting is the last thing I’d ever want to do….

Teresa Blader
Olmsted County GIS Specialist
0 Kudos
DougBrowning
MVP Esteemed Contributor

Mm I have calculated guids before yes.  Make sure it is not read only.  It may be something else then.  Not sure if we are talking just the upper code now.  Are you sure poles is getting back values?  FeatureSetByRelationshipName often fails so you may not be getting anything back is why.

Add things like Console(count(poles)) so see if that part is even working.

0 Kudos
Teresa_Blader
Occasional Contributor III

Sorry for any confusion... - any FeatureSetByRelationship expressions are all behaving and responding normally - sometimes it takes a moment, but it gets there. My pole globalid guid field is editable.

I just shared the two expressions to show:

  • 1st: what I'm accomplishing (grabbing other attributes based of the guid of the pole) 👍
  • 2nd: the concept I used to get the new pole globalid [using this example of grabbing nearest centerlines using FeatureSetByPortalID - which works when the sign is moved 👍] but when I swap out the centerlines layer for the Poles layer portal ID and ask to return the nearest pole globalid, it doesn't overwrite the guid field 👎. It does run and return values in the expression designer - so the expression seems to be operational - just like it is for centerlines.
    • Of course, if the guid is not updating when moved - those other FeatureSetByRelationship won't update either because the guid is how I'm calling attributes in.

Do you also see on a key field in the form designer in a related layer where the Editable button is greyed out and the "editing is disabled in the field settings" message? I'm wondering if this is normal behavior or if it's something I need to change first.

This is my Signs feature layer form via Map Viewer:

Teresa_Blader_0-1713816417774.png

Teresa_Blader_1-1713816451657.png

 

Teresa Blader
Olmsted County GIS Specialist
0 Kudos
DougBrowning
MVP Esteemed Contributor

Have you tested text vs GUID?  Not sure if it lets you edit a GUID I guess.  But I thought you wanted it calculated which is not edited it is the bottom option there Calculated Expression.

0 Kudos
Teresa_Blader
Occasional Contributor III

Yep, entering in the expression under calculated expressions is what I'm doing. In my maintenance record table I also pull in the poles globalid into a guid field as well - it is a GUID field, but not the key field, and does not disable editing... so this behavior is not unique to GUID fields in and of themselves but seems to be unique to relationship key fields.

The message I'm seeing related to editing as an indication of a restriction for relationship class key fields. I can edit the guid field using Arcade or SQL.

I have not yet tested the expression with a relationship class key field being text yet as that would require me to overwrite services with a new relationship class - resetting a lot of work for the forms and popups - so last resort here.

Would you be willing to share a screen shot of one of your examples of what you see in one of your form designer layouts for a relationship class key field that is text? Does it show the same message or no?

Teresa Blader
Olmsted County GIS Specialist
0 Kudos