Add endorsement to file

Questions about and code samples for automation process code snippets within Select.
Post Reply
cklahr
Posts: 71
Joined: Tue Oct 27, 2009 3:32 am

Add endorsement to file

Post by cklahr »

Hi,

I'm using the below formula to add an endorsement to files where this endorsement is not already in the file. My issue is that it's adding the endorsement even when it already exists in the file. Does something in the below coding need to be revised?

Thank you,

Code: Select all

from System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *
from SoftPro.OrderTracking.Client.Orders import *
# Add Endorsement "WV-STG-ALTA 13.1" if it does not exist. 
# Context = Order

def NeedsEndorsements():
	HasEND = False  #Set the overall Variable to False

	##Check to see if the Endorsement Code Already Exists
	#for endorsement in Context.Title.Policies[0].Endorsements:
	#	# If a Endorsement Has no Code, go to the next one to evaluate
	#	if not endorsement.LookupCode:
	#		continue
	#	else:
	#		if endorsement.LookupCode == 'ENDORS_WV_11':
	#			HasEND = True

	# Run the AddEndorsement Function if the Endorsement Variable is False.			
	if HasEND == False:
		AddEndorsement('ENDORS_WV_11')

def AddEndorsement(code):
	end = IOrder.CreateNew(Context, 'Endorsement')
	end.LookupCode = code
	endorsements = Context.Title.Policies[0].Endorsements
	endorsements.Add(end)

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

Re: Add endorsement to file

Post by BobRichards »

I'm not sure what the problem is. The code you commented out seems like it should do the trick. I have added my version of function NeedsEndorsements() that has an optimization to stop searching for 'ENDORS_WV_11' immediately after finding it instead of continuing through the list unnecessarily.

Code: Select all

# If first policy has ANY endorsements but none of the endorsement lookup codes is not 'ENDORS_WV_11', add it.
def NeedsEndorsements():
	HasEND = False  #Set the overall Variable to False

	##Check to see if the Endorsement Code Already Exists
	for endorsement in Context.Title.Policies[0].Endorsements:
		# If a Endorsement Has no Code, go to next endorsement
		if not endorsement.LookupCode:
			continue
		
		# If this is our magic lookup code, set flag and exit loop immediately.
		if endorsement.LookupCode == 'ENDORS_WV_11':
			HasEND = True
			break

	# Run the AddEndorsement Function if the Endorsement Variable is False.
	if HasEND == False:
		AddEndorsement('ENDORS_WV_11')
Bob Richards, Senior Software Developer, SoftPro
Post Reply