Select to view content in your preferred language

Field Maps, FeatureSetByRelationshipName, Arcade, Related Tables

3675
23
08-16-2022 07:47 AM
by Anonymous User
Not applicable

Hello,  I am trying to populate a field (Site_ID) in a related table (campground_evaluations) using the arcade function FeatureSetByRelationshipName.  The related feature that I am trying to pull from is called MTH_Campgrounds.

In Field Maps I want to select a point (campground in this example case) and select the related table icon and enter data into the form I created for the table.  Hopefully, this code will reduce the potential for error while inputting data into the table's form.  The feature and table are related using Global IDs.  This is where I am, but I get a Execution Error:Cannot read properties of null (reading 'toString').

var related = FeatureSetByRelationshipName($feature,'MTH_Campgrounds', ["SITE_ID"], false)

var record = First(related)

if (IsEmpty(record)){

  return "No Record Found"

}

return record['SITE_ID']

 

Thanks in advance!

23 Replies
DougBrowning
MVP Esteemed Contributor

There has been many, many posts on here that FeatureSetByRelationshipName has some bugs in it and often does not work.  Change to FeatureSetByName and it should all work better.  You then have to wrap it in Filter to get just the record you want.  It could be slower if a large table since it grabs it all then you filter. But it works.  Also note to add just the field you want and not return geometry which will be faster.

var sql = "PointID = '" + $feature.PointID + "'";
var tbl = Filter(FeatureSetByName($map,"Points", ['DesignLat'], false), sql);

I asked them to add a where clause to FeatureSetByName which would be much more efficient but no word back yet.

I am also not sure you can return null? I would return ''.

Hope that helps

Lindsay
Occasional Contributor

Hi @DougBrowning , I have a similar situation. Not sure if I should be starting a new post here. Sorry if I've hijacked the thread. I want to pull in the block name from another layer into my new polygon. These layers are in the same map. They are not related. I tried following the instructions in this Field maps blog post - May 12, 2022 Common calculated expressions for ArcGIS Field maps  , and then when I couldn't get it to work, did some googling and came across this thread we're in now.

This is the calculated expression I have.

// Create a feature set using the 'Regions' layer in the map
var blocks = FeatureSetByName($map, 'Blocks', ['Block_name'])

// Intersect the current location with the regions and 
// get the first region
var block = First(Intersects($feature, blocks))

// If the current location does intersect a feature, 
// return the name of the region. Otherwise, return null
if (!IsEmpty(block)) {
    return block['Block_name']
} else {
    return ''
}

 Do you notice anything I've missed here or am I using featuresetbyname incorrectly? I haven't used it before, but want to get the Block_name field from the Blocks layer carried into this new layer.

0 Kudos
DougBrowning
MVP Esteemed Contributor

I tend to use block.Block_name instead but what you have there looks like it should work to me.  I would make sure your field name and map name are the proper case.  Like it is maybe Block_Name or something.

Try that then maybe a screen shot of the map to see.

0 Kudos
Lindsay
Occasional Contributor

Hi @DougBrowning . Thanks for your reply. I've checked the casing. It doesn't look like that. I'm not following where you swap out the block.Block_name part and do I keep using "" or '' in that situation?

Both of these layers are view layers. Would that be affecting it?

0 Kudos
DougBrowning
MVP Esteemed Contributor

On the return line I always write it like First(tbl).DesignLat

Yours would be 

return block.Block_name

My intersects I wrote in one line but it should work the same

var plots = Intersects($feature,FeatureSetByName($map,"TerrADat", ["BareSoilCover"], false));
return Average(plots, "BareSoilCover")

What are the geo types of both layers?

I wonder if you are zommed way out?  

Be aware that using $feature as input to this function will yield results only as precise as the view's scale resolution. Therefore values returned from expressions using this function may change after zooming between scales.

0 Kudos
Lindsay
Occasional Contributor

Hi @DougBrowning , I copied in your expression and switched it out with mine, but got this error. 

 

var blocks = Intersects($feature,FeatureSetByName($map,"Blocks", ["Block_name"], false));
return blocks.Block_name

 

Execution Error:Runtime Error: Cannot call member property on object of this type. Block_name

I'm using two polygons published from ArcPro. Separate feature services. Both view layers.

I'm not zoomed out far. I'm pretty close in.

Thanks for advising about the precision. I wasn't aware of that.

I'm going to mull this over more. Thank you for your help.

0 Kudos
DougBrowning
MVP Esteemed Contributor

You need First in there.

return First(blocks).Block_name

If that does not work take out the false part.  That tells it no geo and may be needed.

0 Kudos
Lindsay
Occasional Contributor

Hi @DougBrowning , I've added in First and removed false, but I'm getting this error.

Execution Error:Runtime Error: Cannot call member method on null. Block_name

 

var blocks = Intersects($feature,FeatureSetByName($map,"Blocks", ["Block_name"]));
return First(blocks).Block_name

 

 

 

0 Kudos
DougBrowning
MVP Esteemed Contributor

Sounds like your intersect is not returning any results.  It picks the first one in the table or the area you are zoomed to.  Are you sure the feature has something to intersect to?

You can add a check to see if the result is empty to avoid an error.

var blocks = Intersects($feature,FeatureSetByName($map,"Blocks", ["Block_name"]));

if (Count(blocks) > 0) {
      return First(blocks).Block_name
}
else {

      return "None found"

}

0 Kudos
Lindsay
Occasional Contributor

Hi @DougBrowning , when I test in the preview, the Result returns None found, but after I click ok in Configure form and save the map, close out and re-enter, if I draw a new polygon (zoomed in enough so I can't see the borders of the polygon whose Block_name attribute I'm trying to pick up), it still appears empty in the form and in the pop-up.

0 Kudos