Python Code - Fail condition if Other Contact Name is Present

Questions about and code samples for automation process code snippets within Select.
Post Reply
rfeller
Posts: 3
Joined: Tue Jun 28, 2016 11:00 am

Python Code - Fail condition if Other Contact Name is Present

Post by rfeller »

Hoping this is a quick question and you can steer me in the right direction. I am trying to have the Python code iterate over all the Other contacts and fail the condition if a specific name is found. There will always be at least 3 Other contacts in every order (Other Type: CLIENT, REFERRAL SOURCE, OTHER). The issue I am running in to is it passes the condition unless all of the Other contacts in the order are the specified value.

Here is the code I have is there anything in here that I can tweak?

from System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *

## Context is Other contact
## Fail the condition if Other contact name is one of the following names listed in Names below
## Pass the condition if none of the Other contact names are present

def OtherContactNameExclusionList():
for names in Context.Name:
Names = ['MyTitleCompany, LLC', 'YourTitleCompany, LLC']
if str(Context.Name) in Names:
return False

return True

OtherContactNameExclusionList()

Attached is a screen print of the automation process the red box is where I have this code snippet in question.

I ran in to the same issue when I was just using the automation wizard to look for Other contact with name <> MyTitleCompany, LLC. It would trigger the automation unless all of the Other contacts in the order are the specified value. Logically if it finds any other contacts that are not MyTitleCompany, LLC it triggers the automation.

I think python will offer a more flexible and scalable solution as we are going away from workflows and replacing it with automation processes that will add a sets of task when a specific other contact combinations (CLIENT and REFERRAL SOURCE combination) are present. So I want to prevent an automation from adding tasks to an order if specific names are in contacts. For example I don't want the automation to trigger if MyTitleCompany, LLC is an Other Contact (other type = REFERRAL SOURCE) and YourTitleCompany, LLC is an Other Contact (other type = CLIENT) . So I need a way to exclude those other contact combinations from the automation processes that are adding similar sets of tasks.

Any help or direction you can offer would be greatly appreciated. :)
Attachments
AutomationProcess.png
AutomationProcess.png (38.66 KiB) Viewed 1876 times
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Python Code - Fail condition if Other Contact Name is Present

Post by BobRichards »

I think the basic issue is that in your criteria, you said "and order has a contact with following criteria". That means the criteria code snippet will be passed a contact as the Context (in this case, an Other contact). In fact, Select will call your code for EVERY Other contact in the order until the snippet returns True or Select runs out of Other contacts. You logic can simplified as follows for the Condition Snippet.

Code: Select all

from System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *

def MyFunc():
    # Return True if name IS NOT in list.
    #   Contacts with a blank name will either be empty or None.  Those will return False since added to list below.
    return Context.Name not in ['MyTitleCompany, LLC', 'YourTitleCompany, LLC', '', None]

MyFunc()
Let me know how it goes.
Bob Richards, Senior Software Developer, SoftPro
rfeller
Posts: 3
Joined: Tue Jun 28, 2016 11:00 am

Re: Python Code - Fail condition if Other Contact Name is Present

Post by rfeller »

Thanks Bob. Apologize for the delayed response. I was able to get help with this and wanted to post the fix just in case other developers can benefit from it.

from System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *

## Context is Other contact
## Fail the condition if Other contact name is one of the following names listed in Names below
## Pass the condition if none of the Other contact names are present

def OtherContactNameExclusionList():
foundContact = False
for other in Context.Others:
Names = ['ContactName1', 'ContactName2']
if other.Name in Names:
# If found, set foundContact to True
foundContact = True

# If no ContactName1 contacts were found (foundContact is still False), pass this condition
if foundContact == False:
return True

OtherContactNameExclusionList()
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Python Code - Fail condition if Other Contact Name is Present

Post by BobRichards »

I really appreciate you posting the fix. Many devs just need to look at working code to get their bearings in new areas. Thanks!
Bob Richards, Senior Software Developer, SoftPro
Post Reply