Select to view content in your preferred language

How to auto calculate related record from table into feature layer in Field Maps?

05-08-2023 07:15 AM
New Contributor

I have a related table and a line feature layer in AGOL. I am trying to create a form in Field Maps that automatically calculates the latest record from the related table and populates it into a comparable field in the line feature layer.

I tried writing a script in Arcade that would read the feature attribute "DelitterRoundNumber" from the table and then calculate it in the form for "Delitter Round" in the feature layer: 

"FeatureSetByRelationshipName($feature, "DELITTERSERVICEDETAILS", ['DelitterRound'])"

Context: I am setting up a Delittering Field Map for a refuse department. The laborers who will collect litter at designated locations will collect attributes including what Round Number they are on. When the laborers collect for a specific round number (i.e. 1-5) that round number will be auto populated or calculated into the "Round Number" attriubte of the line feature layer.  



0 Kudos
2 Replies
Regular Contributor II

I could be wrong, but I think the "Calculated value" code only runs when the form first opens.  So at the time the code is looking at the field in the related table, it is probably an empty field....correct??

You could try setting a default value for that field, and then see if your code works to at least start figuring out what is happening.

0 Kudos
New Contributor

That was a good idea, and I did try and set a default value for the related table, but it led to an additional error in field maps "Unable to calculate field".

I tried the Max function before, and that did auto-calculate after populating a value in a table. 
Here is my arcade code for the calculation into the feature layer. Maybe you can point out where I am going wrong?
// Get the feature set for the delitter rounds
var d_round = FeatureSetByRelationshipName($feature, 'DELITTERSERVICEEDETAILS', ['DelitterRound'], true)

// Get the first delitter round (should only be one)
var lastround = First(d_round)

// If there was a delitter service, return the round of it,
// Otherwise, return null
if (!IsEmpty(lastround)) {
return lastround['DelitterRound']
} else {
return null
0 Kudos