Error running arcade expression in Form

548
10
12-04-2023 11:28 AM
BrianBulla
Occasional Contributor III

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

Why are you returning a full dictionary and not just the value?

Just

if (thisHydrant == null)

        return "WR"

should do it.  You are calculated a value where your code looks more like a rest call.

I assume you are using Field Maps Designer for this.

0 Kudos
BrianBulla
Occasional Contributor III

Well, I coded it like that since when I was doing this in ArcGIS Pro, that was the only way I could get it to work.  I'm trying to update an attribute in a feature, not make any change to the form.

Either way, I don't think FieldMaps has the ability to do what I want to do.  I've tried this so many ways, it's making my head spin.  I think I just need to come to the realization that Field Maps just can't do it and look at other options.

VertiGIS seems to be able to do it, but I hate that application so much.  It's such a pain to work with.

0 Kudos
DougBrowning
MVP Esteemed Contributor

In Field Maps you are calculating a value, it is not an attribute rule like you are used to.  I think Field Maps can do it, I use stuff like this a lot.  Try the code above.  If not show where and how you are adding it in and we can figure it out.

0 Kudos
BrianBulla
Occasional Contributor III

Hi Doug,

Thanks for helping.

So I am setting this code on the respective field on the "Inspections" form.  See the screenshot below:

BrianBulla_0-1701789993057.png

 

Now if I change the code as per your advice above 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 "WR";
};

 

Now when I do this, I still don't get what I want.  What is happening is that a "WR" is now getting substituted for the "switch" control.  But what I want, is for the switch control to update the feature based on wether or not the switch is in the No or Yes position.....if that makes any sense.

BrianBulla_1-1701790401192.png

 

Ultimately what I want to do is replicate what we currently have working in our ArcPad inspection applications.  So the user clicks on a hydrant, an inspection form opens up and based on what is selected in the inspection form, the INSP_STATUS field on the hydrant gets updated.....either to "WR" (work required) or to "YES" (a completed inspection with no issues).

All of these Inspections are saved in a related table to the hydrant....the INSPECTIONS table.  I guess with Field Maps we could have the technician doing the inspection manually toggle the INSP_STATUS on the feature after each inspection to either WR or YES, but I'm trying to avoid them having to do that, as ultimately that will get screwed up in the field and hydrants that should be at WR will get missed.

Currently in ArcPad, this all automated through a script when they hit the "Save" button at the end of the inspection.  So ideally with Field Maps, once they hit the "Submit" button after they fill out the entire inspection form, is where this business logic would happen to determine how to update the INSP_STATUS field on the hydrant.  For now, I am just trying to get it to work with the one field CHAINS, but in reality I would need to look at about 10 different fields before I determine whether to set it to WR or to YES.

Hopefully this makes sense.  This is something I've been trying to sort out with esri for years, and there is still no solution.  I've met with people at the Dev Summit, sat in countless web demos of Fields  Maps and still there is no solution to this.

Hopefully you have some ideas that can point me in the right direction.

Recently I've looked at the Maps SDK, but I'd like to stick to something more simpler than redeveloping all 9 of our field inspections apps from scratch in the Maps SDK.  Not sure we have the manpower for that.

0 Kudos
DougBrowning
MVP Esteemed Contributor

Ok I think you can change what the switch means there on the side.  Change the yes to WR if that is what you want.  All you are doing is changing the domain values.  Sorry if not getting it but seems easy enough.

DougBrowning_0-1701792052374.png

 

0 Kudos
BrianBulla
Occasional Contributor III

Yes, that would change the value for the CHAINS field in the INSPECTION form, but what I need it to do is to change the INSP_STATUS on the hydrant feature.

0 Kudos
DougBrowning
MVP Esteemed Contributor

I guess you are losing me.  If you want Yes No just change the code.  Also have it check for Yes not No I think

if ($feature.CHAINS == "Yes")
{

return "Yes";
};

0 Kudos
TracyLove
New Contributor II

"the user clicks on a hydrant, an inspection form opens up and based on what is selected in the inspection form, the INSP_STATUS field on the hydrant gets updated.....either to "WR" (work required) or to "YES" (a completed inspection with no issues)."

Yeah you should be able to do that but you cant. arcade code only has the ability to effect the feature.attribute it is attached to. if i am incorrect on this please please please show me how. to determine if work is required your INSP_STATUS field will have to check if $feature.CHAINS == yes, $feature.PAINT == yes etc and return WR to the INSP_STATUS field if any are yes. 

furthermore (if i follow you) you are trying to set INSP_STATUS in a featureset/layer that the form isnt attached to. which makes sense from a organization standpoint but isn't possible within fieldmaps/arcade. Once again i hope i am wrong on this. 

i would create a separate python solution to (every night) read the table the form is attached to and then make changes in the INSP_STATUS field in the separate hydrants layer.  its a poor solution to not being able to fully control the form and the related attributes fully in the field.

 

 

0 Kudos
BrianBulla
Occasional Contributor III

Hi @TracyLove .  Yes, it sounds like you understand what I am trying to do.  I agree, I don't think it's possible, but really is something that should be able to be done.  Back in the summer I sat in on a Field Maps webinar where they said that Attribute Rules would soon be coming to Field Maps, and that what I was trying to do should be able to work.

Even at the Dev Summit I talked to esri people who said it should work too, but alas.....nothing works.

We are looking at using VertiGIS Mobile for this now, but I really hate that application.  I think we can get it to work, but it's such a klunky application and to get things working takes a lot of trial and error.  Field Maps is much more user friendly.

Right within ArcPro I can get everything I was to do working with Attribute Rules, it's just within Field Maps that I can't get thing working.

0 Kudos