Is there a way to prevent updating certain attributes when editing?

543
5
Jump to solution
12-20-2023 09:27 AM
AyeletGreenberg
Occasional Contributor

I have a point layer with (1:M) related tables; I use Field Maps for adding/updating the geometry and Survey123 for the forms (related tables).

The layer has a unique ID field that is created with this code: Text(Now(), 'MM DD Y hh mm ss').
This ID is the common key between the geometry and the tables. (I prefer using this readable ID over GlobalID).

The problem is that if I later update the location or any of the attributes of the point, the ID changes as well (based on the time of the updates), and it breaks the relationships between the geometry and the related table (that is still referring to the original ID).  
Is there a way to prevent updating certain attributes when editing, so the ID is generated and assigned only during the initial creation of the point feature?

AyeletGreenberg_0-1703093386870.png

 

 

 

0 Kudos
1 Solution

Accepted Solutions
HollyTorpey_LSA
Occasional Contributor III

I agree with Doug. If you're not sure what that looks like, here's an example:

if (!IsEmpty($feature.ID)) {
  return $feature.ID
} else {
  return Text(Now(), 'MM DD Y hh mm ss')
}

 

- Holly

View solution in original post

5 Replies
marksm_macomb
Occasional Contributor

I'm not sure about a method to prevent certain fields from being edited when a feature is updated, but I thought of a workaround for your specific case.

Could you turn on editor tracking and have the ID field calculate based on the "Created On" date field? The Created On editor tracking field will only populate the moment the feature is created, and does not change every time the feature is updated. 

DougBrowning
MVP Esteemed Contributor

I assume you mean in Arcade?  You can try IsEmpty to check the field and only calculate the first time.  Copy can get you though.

HollyTorpey_LSA
Occasional Contributor III

I agree with Doug. If you're not sure what that looks like, here's an example:

if (!IsEmpty($feature.ID)) {
  return $feature.ID
} else {
  return Text(Now(), 'MM DD Y hh mm ss')
}

 

- Holly
AyeletGreenberg
Occasional Contributor

Both are good ideas. Thanks a lot!

RhettZufelt
MVP Frequent Contributor

You can also limit execution based on the edit type.

if ($editcontext.editType == 'UPDATE') {
  if(!IsEmpty($feature.ID)) {
    return $feature.ID
  }
}

 

Will only fire if you are Updating an existing feature, can use "INSERT" to have it fire on new features.

R_

0 Kudos