Select to view content in your preferred language

Error running arcade expression in Form

1216
10
12-04-2023 11:28 AM
BrianBulla
Honored Contributor

Hi,

So I'm trying customize a fields maps form to automatically update an attribute on a feature when a specific attribute on the form gets set to "YES" (via a form switch).

The form is on a related table called INSPECTIONS, which is related to my HYDRANTS layer.  I want it so when the user sets the switch for CHAINS to be "YES", that the INSP_STATUS field on the HYDRANTS layer gets set to "WR" (for 'Work Required).

On my Field Maps inspection form, I have the Arcade code on the CHAINS switch set to this:

var allHydrants = FeaturesetByName($datastore, 'Hydrants', ['FACILITYID', 'ObjectID'], false);
var facility_id = $feature.FACILITYKEY;  //this should be the ID of the currently selected hydrant
var thisHydrant = First(Filter(allHydrants, 'FACILITYID = @facility_id'));

//If the CHAINS field gets toggled to "YES" in the collection form, then we need to update the INSP_STATUS attribute on the feature to YES

if (($feature.CHAINS != "NO"))
{
    //abort if no hydrant was found
    if (thisHydrant == null){return};

    return {
        'edit': [{
            'classname' : 'Hydrants',
            'updates' : [{
                'objectID': thisHydrant.ObjectID,
                'attributes' : {'INSP_STATUS' : 'WR'}
                        }]
                }]
            };
};

 

In field maps, all I get in the form is some text (the dictionary) where the switch should be instead of the code actually getting triggered like an event when the switch gets toggled by the user.

BrianBulla_1-1701717999288.png

 

Is there a way to get what I want to do to work?  Either through Field Maps forms or some other way??  I've given WebHooks a try, but no success, but this seems like something that should be fairly simple to do.

Right in ArcGIS Pro if I create Attribute Rules on the INSPECTION table this will work, but I have been struggling for years to get Field Maps/Collector to work in a more automated way.  

 

10 Replies
DougBrowning
MVP Esteemed Contributor

Ok I think I get it now.  You want a field is a different layer to calc?  Yes you cannot do that it has to be "touched" for any calcs to fire.  So if the user reopened the other layer then it would calc.

I heard attribute rules are coming to AGOL also but its been delayed a few times I think.

For now as posted above a nightly scheduled Python script does the trick rather well.  I would try this before changing to another app.  Would be really easy code.

If you don't need it for symbology and just display then a Arcade in the web map can do it but it gets rather limited.

0 Kudos