Receiving Error when Object was not set/used

Questions about and code samples for adding visibility conditions within Select
Post Reply
B_Hinote
Posts: 41
Joined: Tue Jan 08, 2019 7:20 pm

Receiving Error when Object was not set/used

Post by B_Hinote » Mon Feb 04, 2019 9:02 pm

I am not new to SoftPro, but defiantly new to Python. While I try to find time to learn the various syntax of the Language and then determine what I can and cannot use in SoftPro, I still need to add a few basic filters. :-)

Based on looking at a few examples and the information in this forum, I created a condition that checked the 1st Property State for a match. This all appeared to work as expected. However, as a way to allow me to see ALL Documents regardless of the Visibility Filter, I decided I was going to use the Order.Project field to place a Special Keyword in that would Override Any Standard Conditions and allow me to see the document regardless.

This too appeared to work, right up to the time that I tried to open the Documents Screen and the Test Order never had anything applied to the Order.Project field. I thought I used example logic to address this by adding the "hasattr()" to determine if the object existed, but this did not prevent the "in" statement from iterating the Project Field anyway. The error it returned states "Argument of type 'str' is not iterable."
Again the following works as expected when the project field has any value assign. Can someone please tell me what I am doing wrong or need to change. Thank you,

The Code I am using is as follows:

# 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 == 'UT') or (hasattr(Order,'Project') and '*ShowAllDocs' in Order.Project)

B_Hinote
Posts: 41
Joined: Tue Jan 08, 2019 7:20 pm

Re: Receiving Error when Object was not set/used

Post by B_Hinote » Mon Feb 04, 2019 9:16 pm

Well if this is correct, I may have figured out how to fix it. The following code is no longer returning an error and appears to be working as expected.
Is it correct or should change it another way? I added "str()" around the Order.Project field. Thank you.

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

# Return True if there is a state object and it matches or The Override condition applies.
return (state and state.Code == 'UT') or (hasattr(Order,'Project') and '*ShowAllDocs' in str(Order.Project))

BobRichards
Posts: 1056
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Receiving Error when Object was not set/used

Post by BobRichards » Tue Feb 05, 2019 11:07 am

It should be sufficient to use:

Code: Select all

# Return True if there is a state object and it matches or The Override condition applies.
return (state and state.Code == 'UT') or (Order.Project and '*ShowAllDocs' in str(Order.Project))
The type of Order.Project is a string (one of the six "iterable types" like lists, etc. that can hold a collection of items) since strings are collections of letters. However, the Order.Project property can also have the value "None" if it has never been set and None is not an iterable type since it can never contain a collection of items. That is the source of your error message "Argument of type 'str' is not iterable".

The reason your final version works is because when you converted Project to a string and if its value is None, it was converted to a string "None". The string "None" never matched your search phrase. (By the way, Project is a hard-coded property on Order and never has to be tested for its existence with hasattr().)
Bob Richards, Software Developer, SoftPro

B_Hinote
Posts: 41
Joined: Tue Jan 08, 2019 7:20 pm

Re: Receiving Error when Object was not set/used

Post by B_Hinote » Tue Feb 05, 2019 2:42 pm

Thank you for your response. It is greatly appreciated. :D

Post Reply