Select to view content in your preferred language

Field Maps - Calculating Field to pull data from a feature service not working

147
7
Wednesday
AaronPDXPaul
Regular Contributor

Using Field Maps Designer in AGOL.

FeatureSetByPortalItem() causes Field Maps to hang.

A spinning circle appears when clicking Submit.

This happens using different code, and different feature services.

Next.

FeatureSetByName() removes the Feature Service from the Web Map, after using in Field Maps.

Is Field Maps completely broken when pulling data from a service?

Here is sample code, sent to me by esri support.

var fsShapeFields = FeatureSetByName($map, "Parks", [], false);

var testVal = Intersects($feature, fsShapeFields);
var value = "OUT";

for (var testfeature in testVal) {
    value = "IN";
    break; // Stop at the first intersection
}

return value

Here is code for breaking Field Maps using FeatureSetByPortalItem().

var arcgisPortal = "https://www.arcgis.com/"
var fsShape = '00c4ade0275e4f4c97ac68d20d3c2952'

var fsShapeFields = FeatureSetByPortalItem(Portal(arcgisPortal), fsShape, 0, ['TAXLOT'], false)

var value = "OUT"

var testVal = Intersects($feature, fsShapeFields)

for (var testfeature in testVal) {
  var fsSelection = Within(fsShapeFields, Centroid($feature))
  var fsSelectionFirst = First(fsSelection)

  var fsText = Text(fsSelectionFirst.TAXLOT)
  value = fsText
}
 
return value
 
Thank you

 

0 Kudos
7 Replies
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

Hi @AaronPDXPaul,

In the FeatureSetByPortalItem(Portal(arcgisPortal), fsShape0, ['TAXLOT'], false) you have false at the end. When you set this part of the portal item to false, it will not return the geometry of a feature.

Where you are using Intersects($feature, fsShapeFields) it requires both feature geometries to work.

Try changing FeatureSetByPortalItem(Portal(arcgisPortal), fsShape, 0, ['TAXLOT'], false) from false to True and then try using the Intersects method.

var arcgisPortal = "https://www.arcgis.com/"
var fsShape = '00c4ade0275e4f4c97ac68d20d3c2952'

var fsShapeFields = FeatureSetByPortalItem(Portal(arcgisPortal), fsShape, 0, ['TAXLOT'], True)

var value = "OUT"

var testVal = Intersects($feature, fsShapeFields)

Console( Count( testVal ) )
if( Count(testVal) > 0 ){
	for (var testfeature in testVal) {
	  	var fsSelection = Within(fsShapeFields, Centroid($feature))
	  	var fsSelectionFirst = First(fsSelection)
		
	  	var fsText = Text(fsSelectionFirst.TAXLOT)
	  	value = fsText
		}
	}
 
return value

 

You may need to play around with the script above to see if it will work or test your own. You can always use the playgound to test arcade scripts in the playground page of the arcgis arcade site.

AaronPDXPaul
Regular Contributor

This worked 🙂

How do you test the drop of a point in the playground for Arcade?

I don't see how to test pulling data when a user adds a point

Thank you again,
Aaron

0 Kudos
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

Just create an arbitrary point feature by using the FeatureSet function. There is plenty of documentation on how to create features from scratch using arcade.

The other option is to create a similar rule on two feature classes in a fdgb and testing the behavior there.

AaronPDXPaul
Regular Contributor

For some reason. It only worked that one time. Now, I can't get it to work with more than 10 attempts, and trying different services. Here is the Arcade I'm using.

var arcgisPortal = "https://www.arcgis.com/"
var fsShape = 'fdc32c1afb004dddb2a2b3bf6db5c579'

var fsShapeFields = FeatureSetByPortalItem(Portal(arcgisPortal), fsShape, 0, ['PARCEL_NUMBER'], True)

var value = "OUT"

var testVal = Intersects($feature, fsShapeFields)

Console( Count( testVal ) )
if( Count(testVal) > 0 ){
  for (var testfeature in testVal) {
      var fsSelection = Within(fsShapeFields, Centroid($feature))
      var fsSelectionFirst = First(fsSelection)
   
      var fsText = Text(fsSelectionFirst.PARCEL_NUMBER)
      value = fsText
    }
  }
 
return value
0 Kudos
AaronPDXPaul
Regular Contributor

Esri is looking into why FeatureSetByPortalItem is not Submitting.

It's replicatable by esri.

Esri suggests to use FeatureSetByName.

But as mentioned in this post. I believe that removes the layer from the web map.

What can I do?

This works for you?

0 Kudos
RPGIS
by MVP Regular Contributor
MVP Regular Contributor

Try modifying your intersects function to have ( Geometry($feature) ) as the first argument. It is a bit unclear as to how exactly it works but typically you intersect the geometry of the input feature so you can get the values of the intersecting feature if I am not mistaken.

var arcgisPortal = "https://www.arcgis.com/"
var fsShape = '00c4ade0275e4f4c97ac68d20d3c2952'

var fsShapeFields = FeatureSetByPortalItem(Portal(arcgisPortal), fsShape, 0, ['TAXLOT'], True)

var value = "OUT"

var testVal = Intersects(fsShapeFields,Geometry($feature))

Console( Count( testVal ) )
if( Count(testVal) > 0 ){
	for (var testfeature in testVal) {
	  	var fsSelection = Within(fsShapeFields, Centroid($feature))
	  	var fsSelectionFirst = First(fsSelection)
		
	  	var fsText = Text(fsSelectionFirst.TAXLOT)
	  	value = fsText
		}
	}
 
return value
var fsShapeFields = FeatureSetByName($map, "Parks", [], True)
var testVal = Intersects(fsShapeFields,Geometry($feature))
iif( count( testVal ) > 0 'IN', 'OUT' )

 

I modified your original arcade script to hopefully work the way you want it to.

0 Kudos
AaronPDXPaul
Regular Contributor

This code leaves the App hanging.

It won't submit.

All of the code works in a Web Map.

But not in Field Maps.

Can you get it to work in Field Maps?

0 Kudos