Select to view content in your preferred language

Can Not Get Calculated Expressions to Work in Forms

360
2
Jump to solution
07-25-2024 06:30 AM
Labels (1)
tthomas9
Occasional Contributor

I was hoping someone could help me figure out the issue I am having with configuring forms in New Webmap Viewer. 

I tried to configure my form to automatically fill in a field from an intersecting layer using the code from this article on configuring forms for attribute editing.

The layer I am trying to intersect from is named 'Pole_feat' and I am trying to auto-populate my form to pull the value from the field 'wmextPole_TRMB_COMMENT'. This will save our field workers a tremendous amount of time as this value can get quite long.

When I test my code, it seems to work just fine and return the value I want (please see Image 1). However, when I test it out in field maps, it will only return my else statement of "nothing" (not all poles have this value filled out, so wanted an else statement). 

I have tried the following:

-Verified both are in the same spatial reference

-Turned on snapping of my form's inspection feature

-Removed the else statement

-Verified the coordinates overlap (see Image 2)

-Tried turning on Pole_feat's popups

-Gave the wmextPoleT_TRMB_COMMENT an alias and tried using that

-Verified that the wmextPole_TRMB_COMMENT field has data (again please see Image 2) 

-Tried using both a feature service and map image service of Pole_feat

 

I am at a total loss on what to do to get this field to autopopulate the intersecting pole. Any help would be greatly appreciated.

 

Here is my code:

if (IsEmpty(Geometry($feature))) {
   return; // No geometry to process
} else {
   // Find intersecting 'Pole_Intersect' features
   var poleIntersects = Intersects($feature, FeatureSetByName($map, "Pole_feat"));

   / / Check if exactly one intersecting feature is found
   if (Count(poleIntersects) == 1) {
      // Return the value from 'wmextPole_TRMB_COMMENT' of the first intersecting feature
      return Text(First(poleIntersects).wmextPole_TRMB_COMMENT);
   } else {
         return "nothing";
   }
}

 

This is a screenshot of the example code from the ArcGIS Online Resources:

 

ExampleCode.jpg

 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

You don't need to use Text on a field that's already text. I would guess that in the example given, the ZIP code was a numeric field. But that's not really the issue.

A point-to-point intersection will need to be exact in order to find anything. Further, geometric functions are dependent upon the rendered shapes, so it can actually vary by view scale, etc. I would suggest putting a tiny buffer on the intersection, in case the points are actually slightly disjoint.

Intersects(Buffer($feature, 2, 'feet'), FeatureSetyByName(…))

 Also, are we certain that there aren't multiple points? The way your expression is written, it will get to the "nothing" statement if the number of intersected poles is anything but 1.

Instead of "nothing", why not return `${Count(poleIntersects)} poles` to verify the number of intersecting poles actually found. Maybe it's not nothing, maybe it's 2?

- Josh Carlson
Kendall County GIS

View solution in original post

2 Replies
jcarlson
MVP Esteemed Contributor

You don't need to use Text on a field that's already text. I would guess that in the example given, the ZIP code was a numeric field. But that's not really the issue.

A point-to-point intersection will need to be exact in order to find anything. Further, geometric functions are dependent upon the rendered shapes, so it can actually vary by view scale, etc. I would suggest putting a tiny buffer on the intersection, in case the points are actually slightly disjoint.

Intersects(Buffer($feature, 2, 'feet'), FeatureSetyByName(…))

 Also, are we certain that there aren't multiple points? The way your expression is written, it will get to the "nothing" statement if the number of intersected poles is anything but 1.

Instead of "nothing", why not return `${Count(poleIntersects)} poles` to verify the number of intersecting poles actually found. Maybe it's not nothing, maybe it's 2?

- Josh Carlson
Kendall County GIS
tthomas9
Occasional Contributor

Thanks a ton for the quick response and great advice. You were correct, when I changed the code to the following:

if (IsEmpty(Geometry($feature))) {
   return; // No geometry to process
} else {
   // Find intersecting 'Pole_Intersect' features
   var poleIntersects = Intersects(Buffer($feature, 5, 'feet'), FeatureSetByName($map, "Pole_feat"));

   // Check if exactly one pole
   if (Count(poleIntersects) == 1) {
      // Return the value from 'wmextPole_TRMB_COMMENT' of the pole
      return Text(First(poleIntersects).wmextPole_TRMB_COMMENT);
   } else {
      return Count(poleIntersects) + " poles";
   }
}

This solved the issue! I was getting "0 Poles" as my return count until I added in that buffer code.  Thank you so much.