Defaulting Settlement Agent CDFPointOfContact to 1st Attorney Contact

Questions about and code samples for custom order rules and validation within Select.
Post Reply
B_Hinote
Posts: 57
Joined: Tue Jan 08, 2019 7:20 pm

Defaulting Settlement Agent CDFPointOfContact to 1st Attorney Contact

Post by B_Hinote »

I have been working on a COR that will default the CDFPointOfContact Settlement Agent Code to the 1st Attorney when the property is in and an Attorney States and a Attorney Contact Exists, to the Status Screen Escrow Office Code when assigned or to SoftPro's Rules when neither of the first two options do not apply. However, I am having an issue getting the code to bypass the Attorney logic when the Attorneys Context is not set. I have temporarily swapped the code to a Validate Rule to attempt to debug the logic and will change this back to a Value Rule after resolving the issue.

The error I am receiving is "Error encountered during rule execution. Index was out of range. Must be non-Negative and less than the size of the collection.Parameter name:index".

I know that this has to do with Attorneys Object not being set, but for the life of me, I cannot seem to figure out the right way to accomplish this.

I would greatly appreciate any suggestions to get past this issue.

Code: Select all

def CDFPointOfContact_Contact_Validate(args):
#def CDFPointOfContact_Contact_Value(args):  #Commented for Testing
	attorneyState = False
	foundAttorney = False	# Testing Only
	attorneyStateList = 'AL_CT_DE_GA_HI_IA_KY_LA_ME_MD_MA_MS_NH_NJ_NY_NC_ND_RI_SC_TN_VT_VA_WV'
	escrowCompanyAssigned = False	# Testing Only

	# Exit if processing template.
	if args.Context.Root.IsTemplate:
		args.RaiseInformation('IsTemplate')	#This is used to for testing 
		args.RunDefaultRule()
		return

	# Exit if not fully initialized
	if (args.Context.Parent is None):
		args.RaiseInformation('Parent is None')	#This is used to for testing 
		args.RunDefaultRule()
		return

	c = args.Context
	if c.Self == c.Parent.Contacts[2]:
		args.RaiseInformation('Processing 3rd CDFPointOfContact')	#This is used to for testing 

		order = args.Context.Root

		# Exit if 1st Property Stte is None
		if order.Properties[0].Address.State is None: 
			args.RaiseInformation('1st Property State is None')	#This is used to for testing 
			args.RunDefaultRule()
			return
	
		# Get state for the first property and then Test to see if it is in the Attorney State List.
		state = order.Properties[0].Address.State
		if (state.Code in str(attorneyStateList)):
			attorneyState = True
			
		args.RaiseInformation('attorneyState = ' + str(attorneyState))	#This is used to for testing
		args.RaiseInformation('1st Property State Code is ' + str(state.Code))	#This is used to for testing 
		args.RaiseInformation('attorneyState = ' + str(attorneyState))	#This is used to for testing 
		args.RaiseInformation('attorneyStateList = ' + str(attorneyStateList))	#This is used to for testing 
		
		if (attorneyState == True and order.Attorneys[0].Name is not None and order.Attorneys[0].Name != ''):
			foundAttorney = True
			args.RaiseInformation('Set SetAgtCd on Page 5 to ' + str(order.Attorneys[0].Code))	#This is used to for testing 
			#args.Value = order.Attorneys[0].Code)
			return
			
		# If Not set to the Attorney Contact, then see if it can be set to the Escrow Satus Company.
		if (order.Escrow.Office is not None):
			escrowCompanyAssigned = True
			args.RaiseInformation('Set SetAgtCd on Page 5 to ' + str(order.Escrow.Office))	#This is used to for testing 
			#args.Value = order.Escrow.Office
			return
		
		# Default to SoftPro's Rules when not Attorney State and No Escrow Status Contact Assigned
		args.RaiseInformation('Run SoftPro Default Rules')	#This is used to for testing 
		args.RunDefaultRule()
		return
Thank you.
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Defaulting Settlement Agent CDFPointOfContact to 1st Attorney Contact

Post by BobRichards »

Have you set a breakpoint on a line and traced where the error is occurring?
Bob Richards, Senior Software Developer, SoftPro
B_Hinote
Posts: 57
Joined: Tue Jan 08, 2019 7:20 pm

Re: Defaulting Settlement Agent CDFPointOfContact to 1st Attorney Contact

Post by B_Hinote »

When testing the Attorney Contact and there is not one assigned to the order.
Image
Attachments
Here is the error
Here is the error
Screenshot 2020-11-16 171918.jpg (151.1 KiB) Viewed 2804 times
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Defaulting Settlement Agent CDFPointOfContact to 1st Attorney Contact

Post by BobRichards »

The problem is that if it is an attorney state, you are returning the first instance in the Attorneys list - whether of not there were any attorneys in the list. If there are no attorneys in the order then indexing the first item (attorneys[0]) is illegal because it does not exist.

The code below is almost identical to yours but I am requiring that there be at least one attorney in the list. I also shortened the if statement to use the knowledge that any non-zero value will be interpreted as "True" (order.Attorneys.Count) and any string that is not None nor empty string will be "True" also (order.Attorneys[0].Name).

There is absolutely nothing wrong with comparing to True/False/None! Code should be written to allow others to maintain it in the future. Sometimes all the extra typing can get in way of understanding the intent when you are debugging code with lots of tests. It is entirely a judgement call. (And as always, your mileage may vary. :D )

Code: Select all

if (attorneyState and order.Attorneys.Count and order.Attorneys[0].Name):
	args.Value = order.Attorneys[0]
	return
Bob Richards, Senior Software Developer, SoftPro
B_Hinote
Posts: 57
Joined: Tue Jan 08, 2019 7:20 pm

Re: Defaulting Settlement Agent CDFPointOfContact to 1st Attorney Contact

Post by B_Hinote »

Bob,

Thank you for your example. It solved the primary issue I was having.
Post Reply