Using "Contains" in Mapping

Questions about and code samples for automation process code snippets within Select.
Post Reply
Posts: 1
Joined: Thu Mar 05, 2020 9:43 am

Using "Contains" in Mapping

Post by SGore » Wed Nov 11, 2020 6:11 pm

Is there a way to use "name contains" in mapping? I'm trying to allow for multiple versions of a contact name.
Ex: Wells Fargo Inc, Wells Fargo Mortgage, etc.

Code: Select all

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


# Get the contact by contact code
def getContactByType(type):
	contact = Context.Others.Where(lambda c: c.OtherType.lower() == type).FirstOrDefault()
	return contact
lender = Context.Lenders[0].Name.ToUpper()
# Dictionary to map Lender names to Final Policy Lender
# Update as necessary (use upper case)
mapping = {'WELLS FARGO':'WF1', 'Bank of America':'BOA1', 'City Bank':'CTY1'}
other = getContactByType('final policy lender')
# if we have both contacts and found a dictionary key
# then set the name value for the Other Contact - Final Policy Lender
if other is not None:
	if lender in mapping:
		other.LookupCode = mapping[lender]

Posts: 1007
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC

Re: Using "Contains" in Mapping

Post by BobRichards » Wed Nov 11, 2020 6:40 pm

Try this. Change the mapping to a list of value pairs. This groups the items in a similar way to the dictionary you had before but in a easier way to do a partial search.

Code: Select all

('AXIA FINANCIAL', 'PL068'), ('U.S. BANK', 'PL782')]
The first map pair (map[0]) is ('WELLS FARGO', 'PL867'). The second map pair (map[1]) is ('FAIRWAY INDEPENDENT MORTGAGE', 'PLIG369').

Now replace the search for the name ("if lender in mapping:") with a different kind of search.

Code: Select all

if other is not None:
	# If bank name in map pair (first item of each pair) is somewhere in the lender then we have a match.
	#    Even matches if lender name has more words than mapping.
	#    If there are no matches, we will set otherLUCode to "None".
	otherLUCode = next((t[1] for t in map if t[0] in lender.upper()), None)
 	if otherLUCode is not None:
 		other.LookupCode = otherLUCode 
Using the next() function is a very efficient way of searching for matches. It stops when it finds a match while some search methods will keep going until the end of the list of things to check.
Bob Richards, Software Developer, SoftPro

Post Reply