Calculated expression intersect results in "Failed to Calculated"

374
5
09-13-2022 07:32 AM
DamonBreen
New Contributor III

Hi all,

I have a map that has a point layer "Gas Leak" and then a set of polygons called "Map Sections". I have set up a field in the Gas Leak layer, called Map Section Number. I have then set this to be a calculated field within the smart form editor for Field Maps. When I press the test button in the web app, it returns the correct map section number that that point is in. But when I try this on Field Maps for IOS, it just tells me "Failed to Calculated" I have manually added the point in several locations around the map to see if it is just a glitch with a particular map or something, and that does not change anything. The expression I am using for this is: 

var MapSections = FeatureSetByName($map,"Map Sections")

var MapSection = First(Intersects($feature,MapSections))


if(!IsEmpty(MapSection)){
Return MapSection.Map_Sectio;
} else {
return NULL
}
0 Kudos
5 Replies
DougBrowning
MVP Esteemed Contributor

I do not think Feature set is supported yet.  You should see a warning like in this post, do you?

https://community.esri.com/t5/arcgis-field-maps-questions/field-maps-featuresetbyrelationshipname-ar... 

0 Kudos
DamonBreen
New Contributor III

I have many related tables and feature layers that share data over the relationships using calculated fields in field maps that work fine. I have read about the FeatureSetByRelationshipName not working properly in field maps, but have had no problems using FeatureSetByName. I do not get that error message, no.

It was a bit hard to follow which problem each reply was regarding reading through that post, but it seems that Lindsey was trying to do this in map viewer, and not Field Maps, yes? There is actually a bulletin that got pushed out when calculated expressions were first released, and what I am trying to do here is actually one of the examples, So I'm not sure why it wouldn't work.

https://www.esri.com/arcgis-blog/products/field-maps/field-mobility/common-calculated-expressions-fo...

0 Kudos
DougBrowning
MVP Esteemed Contributor

Looks like it is only not supported for visibility, sorry was not sure.  

I do see some minor issues with your code (case is wrong on the first return) and I would try not using Null at first just to make sure (I think it is Null BTW).
Also I am not sure IsEmpty will work right so use Count.  I would also test doing a return of Count() to make sure intersects is finding something.  

Is this a typo?  Seems weird to leave the n off here?  MapSection.Map_Section;

You can also add the field name to the FeatureSet call to make it faster.

try

 

var MapSections = FeatureSetByName($map,"Map Sections", ["Map_Sectio"])

var MapSection = First(Intersects($feature,MapSections))


if(Count(MapSection) > 0){
    return MapSection.Map_Sectio;
} 
else {
  return "Nothing found"
}

 

Hope that does it

0 Kudos
DamonBreen
New Contributor III
  • I do see some minor issues with your code (case is wrong on the first return) and I would try not using Null at first just to make sure (I think it is Null BTW).

I did not try to alter this one, as I have a few other codes that return a Null with success, I think Null is OK.

  • Also I am not sure IsEmpty will work right so use Count.  I would also test doing a return of Count() to make sure intersects is finding something. 

I have attached two screenshots below showing the difference when swapping between Count and IsEmpty. Count seems to error out, while IsEmpty returns the correct map section.

  • Is this a typo?  Seems weird to leave the n off here?  MapSection.Map_Section;

Yeah, these map sections are derived from a shapefile so they had some truncations to them that I just didn't bother fixing. It does look weird, but that is the field name for it. I

I don't think there is anything wrong with the code for it, despite a couple flaws here and there. It works when I test it in the expression builder as it should. It just fails to calculate on the iPhone itself. 

I am beginning to wonder if this could be a problem because the map sections were added to the map independently from everything else. I uploaded the map with only the point feature, and the related tables. I added the polygons for map sections after uploading through the add from file option in map viewer. I'm currently working on reuploading the map for a different reason and will include the map sections in the database in Pro and see if it makes a difference. 

If you've got any other ideas, I'm game to try them though! Thanks for the help so far!

 

DamonBreen_0-1663158870692.png

 

DamonBreen_1-1663158906539.png

Damon

0 Kudos
DougBrowning
MVP Esteemed Contributor

Ahh opps I forgot you have first in there.  Need to do count before that.

I would start with 

var MapSections = FeatureSetByName($map,"Map Sections", ["Map_Sectio"])

var MapSection = Intersects($feature,MapSections)

return Count(MapSection)

and see what you get.  I have a feeling it is not finding anything.  

On Null.  I think Null is ok just not sure about NULL since case matters. 

Is your field maps up to date?  FeatureSet is rather new. 

Is it a downloaded map or live?  If downloaded the polygons would need to be in the offline area.  

In your map is the spelling and case for the polygon layer exactly Map Sections.

Try that if not you can DM me and share it if you want.  Else tech support.  Good luck.

0 Kudos