Multiple Properties in Different States

Questions about and code samples for adding visibility conditions within Select
Post Reply
Ppercefull
Posts: 2
Joined: Sat May 22, 2021 5:17 pm

Multiple Properties in Different States

Post by Ppercefull »

I have the visibility code for finding the first state but I need a code if there are multiply properties in different states. I used the below code in a file that has a property in TN and two properties in AL. The first property is in TN so this didn't work because it only looked at the first property. Is there way to iterate through multiple property states?

# Get state for first property.
state = Order.Properties[0].Address.State

# Return True if there is a state object and it matches.
return state and state.Code == 'AL'
BobRichards
Posts: 1382
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Multiple Properties in Different States

Post by BobRichards »

Try this. The code will look at each property in the order. If it finds a state in the
Valid States list, it will immediately exit and return True. Otherwise, it returns False.

Code: Select all

# List of all states that should allow document to be visible.
ValidStates = ["AL", "TN"]

for prop in Order.Properties:
    # Make sure state "Code" exists.
    if (prop.Address is None
        or not str(prop.Address.State)):
        # Not a valid state. Go to next property.
        continue
    
    # We have a value like "NC". Return True if in our list.   
    if str(prop.Address.State) in ValidStates:
        return True

# No order properties in our list of valid states.
return False
Bob Richards, Senior Software Developer, SoftPro
Ppercefull
Posts: 2
Joined: Sat May 22, 2021 5:17 pm

Re: Multiple Properties in Different States

Post by Ppercefull »

That worked thanks!!
Post Reply