Make field value change if value changes in another field

2474
9
Jump to solution
10-21-2021 03:53 PM
martabescansa7
New Contributor II

Hi, 

I have a shapefile with 12000+ parcels and in each one different fields have null values. I need to fill in the information in all of them so in order to track my progress I created a new field called 'Missing' according to what is missing in each parcel using this code: 

-------------------------------------------------------------------------------

Missing =
calc(¡Plotno!,¡Activity!,¡AllowedHei!)


def calc(Plotno, Activity, AllowedHei):
     if Plotno is None and Activity is None and AllowedHei is None:
             return 'Plotno, Activity, AllowedHeight'
    elif Plotno is None and Activity is None and AllowedHei is not None:
             return 'Plotno, Activity'
    elif Plotno is None and Activity is not None and AllowedHei is not None:
            return 'Plotno'
    elif Plotno is not None and Activity is None and AllowedHei is None:
            return 'Activity, AllowedHeight'
    elif Plotno is not None and Activity is None and AllowedHei is not None:
            return 'Activity'
    elif Plotno is None and Activity is not None and AllowedHei is None:
           return 'Plotno, AllowedHeight'
    elif Plotno is not None and Activity is not None and AllowedHei is None:
          return 'AllowedHeight'
    else:
          return 'Complete'

-------------------------------------------------------------------------------------------

This worked perfectly but when I modify anything on my table (eg. I add Plotno information on a parcel that had a null value on that field) the value in the 'Missing' field won't change accordingly. Is there any way to update the 'Missing' field everytime I enter information? That would be super helpful to track my progress. 

Many greetings,

Marta

0 Kudos
2 Solutions

Accepted Solutions
DominicRoberge2
Occasional Contributor III

Hey Martha

once you load you data in AGOL, create an Arcade expression using this code. Let me kn ow if you have any questions.

 

var plotno = $feature.PlotNo;
var activity = $feature.Activity;
var AllowdHei = $feature.AllowedHei;

var missing = When(
    IsEmpty(plotno) && IsEmpty(activity) && IsEmpty(AllowdHei),"Plotno, Activity, AllowedHeight",
    IsEmpty(plotno) && IsEmpty(activity) && !IsEmpty(AllowdHei),"Plotno, Activity",
    IsEmpty(plotno) && !IsEmpty(activity) && !IsEmpty(AllowdHei),"Plotno",
    !IsEmpty(plotno) && IsEmpty(activity) && IsEmpty(AllowdHei),"Activity, AllowedHeight",
    !IsEmpty(plotno) && IsEmpty(activity) && !IsEmpty(AllowdHei),"Activity",
    IsEmpty(plotno) && !IsEmpty(activity) && IsEmpty(AllowdHei),"Plotno, AllowedHeight",
    !IsEmpty(plotno) && !IsEmpty(activity) && IsEmpty(AllowdHei),"AllowedHeight",
    "Complete"
    );
    
return missing;

 

View solution in original post

0 Kudos
DominicRoberge2
Occasional Contributor III

Hey Martha

sorry I didn't read your question correctly. I don't thing the "missing" field will be re calculated automatically. You will have to do that manually. What you could do that would be dynamic is to create a symbology expression using that arcade code and have the symbology based on that "formula". Then if you update PlotNo, that will affect the code therefore the symbology. Then you could update the missing field a few time a day.

Only the symbology and pop-up would be dynamic with the Arcade expression

View solution in original post

0 Kudos
9 Replies
PaulBrandtKCS
New Contributor

Could you move to using a File Geodatabase instead of the Shapefile? I don't think there is a way to do what you are asking in a Shapefile other than saving your calculation as a ModelBuilder model and running it whenever you want to update your 'Missing' field using a selection on the layer, or running on the entire table, but using a File Geodatabase in ArcPro, you would be able to build a Calculation Attribute Rule your calc function could be translated into Arcade if statements and would run with every insert or update on just the row that was changed.

martabescansa7
New Contributor II

Hi Paul,

thanks for your answer. My data is indeed a feature class stored in a database. According to that, I could use Attribute Rules. I have two questions here:

1. What would be the Arcade code for my rule? I literally have no idea of how Arcade works

2. I want to upload the layer to ArcGIS Online so my colleagues can help me complete the missing information. Will the attribute rules work when they are stored in AGOL?

Thanks,

Marta

0 Kudos
DominicRoberge2
Occasional Contributor III

Hey Martha

once you load you data in AGOL, create an Arcade expression using this code. Let me kn ow if you have any questions.

 

var plotno = $feature.PlotNo;
var activity = $feature.Activity;
var AllowdHei = $feature.AllowedHei;

var missing = When(
    IsEmpty(plotno) && IsEmpty(activity) && IsEmpty(AllowdHei),"Plotno, Activity, AllowedHeight",
    IsEmpty(plotno) && IsEmpty(activity) && !IsEmpty(AllowdHei),"Plotno, Activity",
    IsEmpty(plotno) && !IsEmpty(activity) && !IsEmpty(AllowdHei),"Plotno",
    !IsEmpty(plotno) && IsEmpty(activity) && IsEmpty(AllowdHei),"Activity, AllowedHeight",
    !IsEmpty(plotno) && IsEmpty(activity) && !IsEmpty(AllowdHei),"Activity",
    IsEmpty(plotno) && !IsEmpty(activity) && IsEmpty(AllowdHei),"Plotno, AllowedHeight",
    !IsEmpty(plotno) && !IsEmpty(activity) && IsEmpty(AllowdHei),"AllowedHeight",
    "Complete"
    );
    
return missing;

 

0 Kudos
martabescansa7
New Contributor II

Hi Dominic,

thank you for your answer. I have uploaded the data to AGOL, then I selected the Missing field, clicked 'CALCULATE'  and entered the Arcade code. I don't see any changes in the 'Missing' field when I update the other fields in a plot so I guess I am not implementign any attribute rule when doing that....

0 Kudos
DominicRoberge2
Occasional Contributor III

hummm I just tested it here using the following code

var drTest = $feature.testDefaultValue;
var drNewVal = When(
    drTest =='dr_test',"Code1",
    drTest =='test1',"Code2",
    "complete"
    )
return drNewVal;

 

and that got me this:

DominicRoberge2_0-1634928284102.png

 

0 Kudos
DominicRoberge2
Occasional Contributor III

Hey Martha

sorry I didn't read your question correctly. I don't thing the "missing" field will be re calculated automatically. You will have to do that manually. What you could do that would be dynamic is to create a symbology expression using that arcade code and have the symbology based on that "formula". Then if you update PlotNo, that will affect the code therefore the symbology. Then you could update the missing field a few time a day.

Only the symbology and pop-up would be dynamic with the Arcade expression

0 Kudos
martabescansa7
New Contributor II

Hi Dominic, I did what you say applying the formula to a new symbology called 'Missing_info'. It works but as soon as I select a polygon and I start editing the symbology disapears....so I guess there is no cool way to keep track of whats missing in ArcGIS Online...

0 Kudos
DominicRoberge2
Occasional Contributor III

perhaps there is an issue with the formula. Other things to keep in mind. 

1) make sure you have all options available when creating the symbology (in my case I don't have records with value 'test2' yet therefore it's not an option when creating the symbology)

DominicRoberge2_1-1634939369448.png

 

2) Otherwise, make sure to select the Other option

DominicRoberge2_0-1634939243384.png

it should work. Good luck!

0 Kudos
martabescansa7
New Contributor II

my bad...i forgot to save the symbology expression, that's why it was dissapearing...

Your solution works both in AGOL and when I edit the map in ArcGIS Pro importing it from AGOL, many many thanks!!

By the way..noticed the subtypes and domains would not work when uploading the layer to AGOL...a workaround is to always upload the layer with the numeric subtype field in ArcPro and it won't give problems.

Thanks again!!