Problem with calculated expression and editable expression

297
3
02-16-2024 10:36 AM
Tiff
by
Occasional Contributor III

I have a calculated expression that automates an ID based on spatial features and sequential numbering. This expression is set to calculate upon inserts (aka creating new points).

Smart Forms now allows you to set an expression for the editable logic. I wanted to allow edits for existing points, with the following code below. This works perfectly, however...

 

 

if($editcontext.editType == "UPDATE"){
    return true
  }
else{
  return false
}

 

 

My problem now is I am trying to add another condition, such as if a field is filled in or not (see code below), but once I do that the calculated expression no longer works. If there is an existing ID, it completely wipes the field and the field becomes null. Is there a reason or a fix? I understand that this is likely hard to test but the problem TLDR is my calculated expression works fine UNTIL I set a specific condition for the editable logic. Any help much appreciated!

 

 

if($editcontext.editType == "UPDATE" && $feature.qaqc == "False"){
    return true
  }
else{
  return false
}

 

 

0 Kudos
3 Replies
JustinReynolds
Occasional Contributor III

Hello,

What do you mean by "..., such as if a field is filled in or not (see code below)"?  To test whether or not a field has a value or not, you need to use the built-in function `IsEmpty`.

 

if($editcontext.editType == "UPDATE" && !IsEmpty($feature.qaqc)){
    return true
  }
else{
  return false
}

 


Also, the code above is a bit verbose and can be simplified a bit.   The else can be implicit with simple expressions like this, since Arcade returns the last executed line of code, unless it encounters another return statement before the end.

 

if($editcontext.editType == "UPDATE" && !IsEmpty($feature.qaqc)){ return true };
return false;

 

- Justin Reynolds, PE
0 Kudos
Tiff
by
Occasional Contributor III

Hi @JustinReynolds, thanks for this. Shortly after I posted this I actually tried the !IsEmpty function as well and it had the same behavior unfortunately, in that adding !IsEmpty wiped out the field, but without !IsEmpty it just left the field as editable for existing points. The reason I tried an == operation is because we are actually searching for a specific value in that field in order to allow edits.

I just tried out your simplified syntax though and still running into that error. Thank you for trying to help figure this out though!

 

 

0 Kudos
Tiff
by
Occasional Contributor III

Hi again @JustinReynolds, thanks for your suggestion. I noticed you were very active in the forums about this topic within the last few years so you have a lot of knowledge about these expressions!

I am curious to see if you have experienced strange functionality between the calculated expression and editable expression. For example as I mentioned above, the moment I have a secondary condition in addition to $editcontext.editType, it wipes out my existing field instead of retaining it. I fixed this by adding a few lines to my calculated expression with an if statement of $editcontext.editType == "UPDATE" to retain originalFeature's field. 

However, I still have really weird behavior in other cases such as:
1) If my editable expression is == "INSERT", so that I can allow edits after it is autocalculated, the calculated expression does not work at all so it is left blank (perhaps that is intentional by Esri)
2) On top of that, if I have a condition in my calculated expression to autocalculate the field if there is a specific string existing in that field, that only works if I have no editable expression at all. If there is no expression and it is an update, then the field gets overwritten correctly. If there is an editable expression as $editcontext.editType == "UPDATE", then the field value stays. No difference in the actual calculated expression, but depending on what's in the editable expression, the behavior is very different.

I am already talking to tech support about this but given your experience I figured I'd ask!

0 Kudos