How to check every seller

Questions about and code samples for adding visibility conditions within Select
Post Reply
svilla
Posts: 7
Joined: Sat Dec 17, 2022 7:15 pm

How to check every seller

Post by svilla »

Hi,
I'm new at this and I need some guidance. We want a document to populate if the seller has an AKA. What is the best way to look at every Seller to see if there is an AKA in that field?
I don't understand how to search every seller. I was looking at the code for loops but how do I count the number of sellers to make the loop work?
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: How to check every seller

Post by BobRichards »

In this script, we examine all the sellers until we either find one with an AKA value or run out of sellers. At the top of the Sellers loop, we move to the next seller if it is any type of organization. If it isn't (therefore, Male, Female, Joint), then we examine the Individual1 AKA property for a value. If so, we return True to allow the document to be visible. If Individual1 doesn't have an AKA property value and this is a joint seller, we check the Invidual2 AKA for a value. Ultimately if we never find an AKA value, we return False.

Code: Select all

# Test every seller in the order.
for seller in Order.Sellers:
	# Skip all organization contact types.
	if seller.BuyerSellerType >= seller.BuyerSellerType.Organization:
		continue

	# We must have an Individual1 property.
	aka = seller.Individual1.AKA
	if aka is not None and len(aka.strip()):
		# First seller individual has an AKA value.
		return True

	# Make sure we have an Individual2 before testing it.
	if seller.BuyerSellerType == seller.BuyerSellerType.Joint:
		aka = seller.Individual2.AKA
		if aka is not None and len(aka.strip()):
			# Second seller individual has an AKA value.
			return True
			
# No AKA found for sellers.
return False
Bob Richards, Senior Software Developer, SoftPro
svilla
Posts: 7
Joined: Sat Dec 17, 2022 7:15 pm

Re: How to check every seller

Post by svilla »

Thank you so much. That works great. Can you explain what "len(aka.strip())" does? Everything else I can follow.
BobRichards
Posts: 1377
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: How to check every seller

Post by BobRichards »

I want to determine if the AKA has printable characters in it - anything except spaces and tabs. The command "aka.strip()" removes all "whitespace" (non-printable characters like spaces and tabs from the front and end of the string).

Code: Select all

v = "   \t  hello  ".strip()  # v = "hello" (remove leading and trailing whitespace)
v = "goodbye".strip()         # v = "goodbye" (no change)
Lastly, I get the number of characters left in the string. In a Python if statement, if the value is not zero, it will be treated as True.
Bob Richards, Senior Software Developer, SoftPro
svilla
Posts: 7
Joined: Sat Dec 17, 2022 7:15 pm

Re: How to check every seller

Post by svilla »

That makes sense.

Following that same logic, I created the following and it's not working. I want to see a folder only if the seller is an organization. Do I need to specify what Organization type in order for this to work?

Code: Select all

# Test every seller in the order.
for seller in Order.Sellers:
	# Only show if seller is an organization.
	if seller.BuyerSellerType == seller.BuyerSellerType.Organization:
		return True

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

Re: How to check every seller

Post by BobRichards »

Really close. Under the covers, we assign a different numerical value to each possible BuyerSellerType. All organization types are 32 or greater. Minor correction to code below.

Code: Select all

# Test every seller in the order.
for seller in Order.Sellers:
	# Only show if seller is an organization.
	if seller.BuyerSellerType >= seller.BuyerSellerType.Organization:
		return True

return False
Bob Richards, Senior Software Developer, SoftPro
svilla
Posts: 7
Joined: Sat Dec 17, 2022 7:15 pm

Re: How to check every seller

Post by svilla »

Hi,
What is the best way to examine a custom field for each seller?

Code: Select all

# Test every seller in the order.
for seller in Order.Sellers:
        # Skip all organization contact types.
        if seller.BuyerSellerType >= seller.BuyerSellerType.Organization:
                continue

        # We must have an Individual1 POA name.
        POA1 = seller.POANameSeller1_SP##
        if POA1 is not None and len(POA1.strip()):
                # First seller individual has a POA value.
                return True

        # Make sure we have an Individual2 before testing it.
        if seller.BuyerSellerType == seller.BuyerSellerType.Joint:
                POA2 = seller.POANameSeller2_SP##
                if POA2 is not None and len(POA2.strip()):
                        # Second seller individual has a POA value.
                        return True
                        
# No POAs found for sellers.
return False

svilla
Posts: 7
Joined: Sat Dec 17, 2022 7:15 pm

Re: How to check every seller

Post by svilla »

Hi,
I was reading an old post about custom fields and it mentions "IOrderItem interface." Is this something we need to be able to use custom fields to create ReadyDoc Visibility Conditions in SoftPro Select?
vmrvichin
Posts: 27
Joined: Thu Jul 22, 2021 11:50 am

Re: How to check every seller

Post by vmrvichin »

In a word no, there is no way use custom fields in determining the visibility for a document.

You are correct that in order to read/write to custom fields the IOrder interface is needed. This is usually brought into python code via an import. However the python code that executes to determine a document's visibility needs to execute quickly as it has the potential to be run against all documents. A result of this speed requirement it means that libraries are not able to be imported into the readydoc visibility python code.
Vlad Mrvichin, Senior Software Developer, Custom Dev, SoftPro
Post Reply