IF Statements based on several fields for Attribute Assistant

04-25-2019 06:33 AM
Occasional Contributor II


I am new to using attribute assistant and need some help. I need to be able to populate a field on the fly called Total Activations (field name TotalActivations) based on Activation1, Activation2, Activation3, Activation4, Activation5, and Activation6.

I can create a script in Python to do this, but not sure how to do it in Attribute Assistant. The reason why i would like to use Attribute Assistant is so that an user does not have to run a script tool every time an update is made. Here is what my table looks like:

If the value is 'Yes' in any of the activation numbered fields, that takes the value of 1, any 'No' or <Null> values takes a value of 0. So the first line item would total 1.

My python script is the following:

import arcpy

poles = 'Test2'
fieldList = ("Activation1", "Activation2", "Activation3", "Activation4", "Activation5", "Activation6", "TotalActivations")

with arcpy.da.UpdateCursor(poles, fieldList) as cursor:
    for row in cursor:
        n = 0
        if row[0] == 'Yes':
            a = 1
        elif row[0] == 'No' or row[0] is None:
            a = 0
        if row[1] == 'Yes':
            b = 1
        elif row[1] == 'No' or row[1] is None:
            b = 0
        if row[2] == 'Yes':
            c = 1
        elif row[2] == 'No' or row[2] is None:
            c = 0
        if row[3] == 'Yes':
            d = 1
        elif row[3] == 'No' or row[3] is None:
            d = 0
        if row[4] == 'Yes':
            e = 1
        elif row[4] == 'No' or row[4] is None:
            e = 0
        if row[5] == 'Yes':
            f = 1
        elif row[5] == 'No' or row[5] is None:
            f = 0
        n = a + b + c + d + e + f
        row[6] = n

How do I translate this into Attribute Assistant?

0 Kudos
1 Reply
Occasional Contributor III


If you can change the activation field types to short and use a domain (0 for No, and 1 for Yes) you will still able to see the Yes /No values in your table.

then in AA you can get the sum of all of your fields in the new field without if statements.

0 Kudos