Calculated Expressions in Forms for Feature to Feature Relates

343
5
Jump to solution
03-15-2024 01:29 PM
Labels (3)
KristalWalsh
Occasional Contributor II

Hi, I'm not sure I'm even close with this script, so I'm hoping someone can help pull me through! The objective here is to intersect two features, pulling one id from one fc into another.  The intersect part of the code works but when creating a second feature (per the form), as in a second property for an existing landowner, there is no intersect, so I just want the customer id from the related customer to be pulled into property fc. I know there's something missing, but I just don't know what or where to add it. Total Arcade novice here.

// Define a Featureset (Customers) from the layer "Customers" in the $map
// that contains the attribute ['CustomerID']

var Customers = FeatureSetByName($map, "Customers", ['CustomerID'])

// Define a variable (code) to store the value we want
// Get the value by Intersecting the polygon location
// with the FeatureSet "Customers", or Customers

var code = First(Intersects($feature, Customers))

// If the current location intersects Customers,
// return the value in the field ['CustomerID'].
// If no intersect, pull customer id into related feature layer [ProertyBoundary]

var relcustid = First(FeatureSetByRelationshipName($feature.CustomerID, "Customers_PropertyBoundary"))

if (!IsEmpty(code)) {
    return code['CustomerID']
} else {
return Console(relcustid["CustomerID"])}
Kristal Walsh, Florida Fish and Wildlife
Office of Conservation Planning
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

You were returning the Console function instead of the CustomerID from the related layer. Give this code a try. I restructured it so it first checks if there's an intersection before getting the related table.

// Define a Featureset (Customers) from the layer "Customers" in the $map
// that contains the attribute ['CustomerID']

var Customers = FeatureSetByName($map, "Customers", ['CustomerID']);

// Define a variable (code) to store the value we want
// Get the value by Intersecting the polygon location
// with the FeatureSet "Customers", or Customers

var code = First(Intersects($feature, Customers));

// If the current location intersects Customers,
// return the value in the field ['CustomerID'].

if (!IsEmpty(code)) return code['CustomerID'];

// If no intersect, pull customer id into related feature layer [PropertyBoundary]

var relcustid = First(FeatureSetByRelationshipName($feature.CustomerID, "Customers_PropertyBoundary"));
return relcustid["CustomerID"];

View solution in original post

5 Replies
KenBuja
MVP Esteemed Contributor

You were returning the Console function instead of the CustomerID from the related layer. Give this code a try. I restructured it so it first checks if there's an intersection before getting the related table.

// Define a Featureset (Customers) from the layer "Customers" in the $map
// that contains the attribute ['CustomerID']

var Customers = FeatureSetByName($map, "Customers", ['CustomerID']);

// Define a variable (code) to store the value we want
// Get the value by Intersecting the polygon location
// with the FeatureSet "Customers", or Customers

var code = First(Intersects($feature, Customers));

// If the current location intersects Customers,
// return the value in the field ['CustomerID'].

if (!IsEmpty(code)) return code['CustomerID'];

// If no intersect, pull customer id into related feature layer [PropertyBoundary]

var relcustid = First(FeatureSetByRelationshipName($feature.CustomerID, "Customers_PropertyBoundary"));
return relcustid["CustomerID"];
KristalWalsh
Occasional Contributor II

Thank you Ken, but it still fails to calculate the customer id value. I'm thinking the error has something to do with the fact that I am selecting an existing customer to edit and add a new related feature. Is the code missing a filter statement somewhere? I just don't know if that's the issue or if it matters. 

Kristal Walsh, Florida Fish and Wildlife
Office of Conservation Planning
0 Kudos
KenBuja
MVP Esteemed Contributor

Line 19 should get the proper customer ID from the related table. What do you want to return if there's no related record?

0 Kudos
KristalWalsh
Occasional Contributor II

There shouldn't be a time when there is no related record, unless of course, staff make a mistake somehow. I'm hoping to have that fool proof once I get this to EB. I've not done much work in EB but assuming I have to get everything functioning correctly here first. I double-checked the relationship class name and it's correct. I'm sure there's a breakdown somewhere on my end, just gotta find it. Thank you for your help.

Kristal Walsh, Florida Fish and Wildlife
Office of Conservation Planning
0 Kudos
KristalWalsh
Occasional Contributor II

@KenBuja we have figured out the problem with my error, and I think I did not describe the workflow accurately.  The intersect works just fine as we established above - a polygon [property] intersects the point [customer] which was placed first and the customer id is pulled into the property attribute. But if I select the customer point, say to add a new property, then choose edit from the pop-up, and then add a new feature, the relationship is broken or rather the customer id defaults to null and the script doesn't work as intended. The customer needs to be selected so that a 1:many relationship is maintained between customer:properties. At this time, I'm not sure what other workflow to use than to have ask the staff to place a point at every location where the customer has a property. Not ideal but at least this way I know the intersect will work and I can maintain a separate related table for all other customer info. If you have any thoughts, they would be greatly appreciated. 

Kristal Walsh, Florida Fish and Wildlife
Office of Conservation Planning
0 Kudos