Select to view content in your preferred language

Autopopulating fields from a related table using Arcade

2332
14
04-11-2023 07:39 AM
DaveK
by
Occasional Contributor

Hello! 

I'm creating a Field Maps collection form which includes a parent point layer as well as a related table. The parent point layer contains a UniqueID field which is a domain that the user will select. Is it possible to auto populate the remaining fields in the parent table from the information in the related table based on the UniqueID chosen? I think the "Fetch an attribute form a related table" from this page - https://www.esri.com/arcgis-blog/products/field-maps/field-mobility/common-calculated-expressions-fo... is the closest to what I'm looking for. Instead of populating the related table from the parent, I would like to auto populate the parent layer from the related table. Any help is appreciated. 

Thanks. 

14 Replies
ErikWalling
New Contributor II

Thank you for the insights! I think I finally beat this into submission. For one thing I had the wrong data type for calculating a decimal number so that definitely helped but this is what I ended up with. 

 

var a = $feature.Scum
var b = $feature.Sludge
var c = $feature.LiquidDepth
var d = ((a + b) / c) * 100
IIf(c == 0, 0, d)
0 Kudos
DougBrowning
MVP Esteemed Contributor

Pretty sure this would crash on var d if c =0 since you are checking it after the fact.

I would do more like 

iif ($feature.LiquidDepth == 0, 0, (($feature.Scum + $feature.Sludge) / $feature.LiquidDepth) * 100)

0 Kudos
ErikWalling
New Contributor II

Surprisingly this actually works as is. The variable "d" does not evaluate to 'true' unless variable "c" is not equal to zero. I kept getting a result of infinity which I believe was due to the calculation trying to divide by zero. 

In the form liquid depth is pulled from the main table using:

var x = FeatureSetByRelationshipName($feature,"MPCVRS", ['LiquidDepth'])
var y =First(x)
if (!IsEmpty(y)) {
    return y['LiquidDepth']
} else {
    return null
}
 
Capacity is then calculated based on user entries for Scum and Sludge using: 
 
var a = $feature.Scum
var b = $feature.Sludge
var c = $feature.LiquidDepth
var d = ((a + b) / c) * 100
IIf(c == 0, 0, d)
 
I then used:
var a = $feature.CalcCap
IIf(a > 33.0, "YES", "NO")
 
to determine if the tank needs to be pumped or not returning domain values "YES" or "NO"
I've successfully tested this multiple times through field maps. 
0 Kudos
DougBrowning
MVP Esteemed Contributor

It may be trying to help you by working but I would not do it that way.  Never want code that divides by 0.  Its as easy fix so why not.

If I remember right var y =First(x) will also fail if x is empty  You need to check x for being empty first.

var x = FeatureSetByRelationshipName($feature,"MPCVRS", ['LiquidDepth'], false);  //faster to not return geo
if (!IsEmpty(x)) {
    return First(x)['LiquidDepth']      // or First(x).LiquidDepth
 
else {
    return null
}
0 Kudos
RhettZufelt
MVP Notable Contributor

Depending on how complex it is, another option would be to just calculate the values in the form for the remaining fields based on what is chosen for UniqueID.

R_

0 Kudos