Exceptions/Requirements – Handling multiple references to order objects

Questions about and code samples for automation process code snippets within Select.
Post Reply
toddsou
Posts: 75
Joined: Wed Jul 25, 2012 9:39 am

Exceptions/Requirements – Handling multiple references to order objects

Post by toddsou »

We utilize automation code snippets to add Requirements/Exceptions to orders if certain criteria are met. Thus far, we have been able to achieve this when the Exception/Requirement content is straight text or it pulls from a very specific data field from the order. We are running into an issue when trying to add a Requirement/Exception that contains field codes that match more than one reference on the order.

Example field code from a requirement: {{Order.ExistingLiens.Mortgagee}} In this field code example, if there is more than one ExistingLien on an order, and we attempt to manually add the requirement, we are prompted with the following (see attached image):
Which judgement to select?
Which judgement to select?
image_2022-10-06_170056247.png (13.93 KiB) Viewed 1165 times
We are using the following syntax when adding a requirement/exception to an order:

Code: Select all

# Create instance of a requirement.
requirement = IOrder.CreateNew(Context, ‘Requirement’)
requirement.Code = TARGET_LOOKUP_CODE
                
# Add new requirement to list of all requirements.
order_commitment_requirements = Context.Title.TitleInsuranceCalculations[0].Commitment.Requirements 
order_commitment_requirements.Add(requirement)

Is there a way we can programmatically handle this type of scenario in an automation code snippet, to reference a specific ExistingLien object, when adding a Requirement/Exception to an order?

Thank you.
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Exceptions/Requirements – Handling multiple references to order objects

Post by BobRichards »

In your case, the lookup code is not unique so when the ILookups service detects this, it fires the DisambiguateLookupRow event. This event passes the handler all lookup table rows that match the criteria and allows the consumer to select the row to accept (or cancel, if desired).

See the SDK Help file topic: How-To / Lookup Tables / Handling Disambiguities for an example of handing this is C#. You'll have to perform the same operation in Python.
Bob Richards, Senior Software Developer, SoftPro
normanc
Posts: 3
Joined: Wed Oct 05, 2022 4:02 pm

Re: Exceptions/Requirements – Handling multiple references to order objects

Post by normanc »

Thank you for your answer on this. I did some additional reading in the SDK on 'Handling Disambiguities', and also read some related posts on the forum, including your very helpful post on how to work with lookup tables (https://devforum.softprocorp.com/viewtopic.php?t=1475). While the lookup table in question does have 'Allow duplicate key field values' enabled, I don't believe this is a scenario that we are running into. The lookup code that I am trying to add in the automation code snippet is unique to that lookup table. This is how the lookup table in question is setup:
RequirementsAndExceptionsLookupTable.png
RequirementsAndExceptionsLookupTable.png (144.94 KiB) Viewed 1136 times
To further test this out and try to find what is happening under the hood, I wrapped code being used to add the Requirement to the order in a Try/Except to see what type of exception we may be running into like this:

Code: Select all

if does_requirement_exist() == False:	
	try:
		# Create instance of a requirement.
		requirement = IOrder.CreateNew(Context, REQUIREMENT_CONTEXT)
		requirement.Code = TARGET_LOOKUP_CODE
		
		# Add new requirement to list of all requirements.
		order_commitment_requirements = Context.Title.TitleInsuranceCalculations[0].Commitment.Requirements
		order_commitment_requirements.Add(requirement)
	except Exception as ex:
		raise ValueError("Exception Type: " + type(ex).__name__)
When the code snippet executes, I do not run into an exception at all. It adds the Requirement to the order, however, the phrases used within the Requirement Text are not pulled from the order. An example from the Requirement specified in the lookup table is {{Order.ExistingLiens.Mortgagee}}; I suppose because the phrase is coded to look at the entire ExistingLiens collection, instead of one specific ExistingLien order field (e.g. Order.ExistingLiens[0].Mortgagee) it is not replacing any of the phrase codes when the requirement is added to the order. It is only when I try to manually add this particular requirement to the order do I get the "Reference to the single Existing Lien was encountered" prompt.

To try to find a work-around, I tried forcing the requirement.Text property from the code, using phrase codes pointing to specific ExistingLien objects like this:

Code: Select all

if does_requirement_exist() == False:	
	try:
		# Create instance of a requirement.
		requirement = IOrder.CreateNew(Context, REQUIREMENT_CONTEXT)
		requirement.Code = TARGET_LOOKUP_CODE
		requirement.Text = "BEGIN TEST: Satisfaction and release of that certain judgment(s) in favor of {{Order.ExistingLiens[0].Mortgagee}} against {{Order.ExistingLiens[0].Mortgagor}} recorded in Public Records Book {{Order.ExistingLiens[0].Recording.BookNumber}} at Page {{Order.ExistingLiens[0].Recording.PageNumber}}, in the amount of ${{Order.ExistingLiens[0].OriginalPrincipalAmount}}, plus interest and cost...END TEST"
		
		# Add new requirement to list of all requirements.
		order_commitment_requirements = Context.Title.TitleInsuranceCalculations[0].Commitment.Requirements
		order_commitment_requirements.Add(requirement)
	
	except Exception as ex:
		raise ValueError("Exception Type: " + type(ex).__name__)
When the code executes, no exception is encountered, and it adds the Requirement text, but does not interpolate any of the field codes used in the Requirement text with the proper values entered on the order.

Ultimately, I will need to find a way to programmatically add multiple Requirements to an order, with each requirement pulling text from a specific ExistingLien object, roughly like this:

Code: Select all

# Get Existing Lien count matching criteria
matching_liens = len([str(lien.InstrumentType.Description) for lien in Context.ExistingLiens if str(lien.InstrumentType.Description) == INSTRUMENT_TYPE])
		
# Add new requirements to list of all requirements.
order_commitment_requirements = Context.Title.TitleInsuranceCalculations[0].Commitment.Requirements

for lien in matching_liens:
	order_commitment_requirements.Add(requirement)   # Not sure how to specify which ExistingLien to reference here, as seen when manually adding the requirement to the order
Given the use of non-specific phrase codes used in Requirement text like {{Order.ExistingLiens[0].Mortgagor}}, is what I am trying to do feasible? In looking around the Field Code Browser, I did find a "Phrases" property associated with the Requirements object, but I was unsuccessful in trying to work with this either through automation snippets nor via Custom Order Rules to see if I could maybe see what their values looked like via args.RaiseInformation()

Thank you again for your time and info!
normanc
Posts: 3
Joined: Wed Oct 05, 2022 4:02 pm

Re: Exceptions/Requirements – Handling multiple references to order objects

Post by normanc »

I found a work-around for this scenario: Using the below code I am able to add multiple Requirements, and then manually set the non-specific field codes used in the Requirement Text.

Code: Select all

# Get Existing Liens matching criteria
matching_liens = [lien for lien in Context.ExistingLiens if str(lien.InstrumentType.Description) == INSTRUMENT_TYPE]

# Add new requirements to list of all requirements.
order_commitment_requirements = Context.Title.TitleInsuranceCalculations[0].Commitment.Requirements

for lien in matching_liens:	
	# Add requirement to order
	requirement = IOrder.CreateNew(Context, REQUIREMENT_CONTEXT)
	requirement.Code = TARGET_LOOKUP_CODE
	order_commitment_requirements.Add(requirement)
			
	# Update requirement phrases
	last_index = len(order_commitment_requirements) - 1
	order_requirement = order_commitment_requirements[last_index]
	order_requirement_text = IOrderItem.GetProperty(order_requirement, 'Text')
	if lien.Mortgagee is not None:
		order_requirement_text = order_requirement_text.replace('\{\{Order.ExistingLiens.Mortgagee\}\}', lien.Mortgagee)
	if lien.Mortgagor is not None:
		order_requirement_text = order_requirement_text.replace('\{\{Order.ExistingLiens.Mortgagor\}\}', lien.Mortgagor)
	if lien.Recording.BookNumber is not None:
		order_requirement_text = order_requirement_text.replace('\{\{Order.ExistingLiens.Recording.BookNumber\}\}', lien.Recording.BookNumber)
	if lien.Recording.PageNumber is not None:
		order_requirement_text = order_requirement_text.replace('\{\{Order.ExistingLiens.Recording.PageNumber\}\}', lien.Recording.PageNumber)
	if lien.OriginalPrincipalAmount is not None:
		order_requirement_text = order_requirement_text.replace('\{\{Order.ExistingLiens.OriginalPrincipalAmount\}\}', "{:,.2f}".format(float(lien.OriginalPrincipalAmount)))
	IOrderItem.SetProperty(order_requirement, 'Text', order_requirement_text)
It is not the most elegant solution, but gets us over the hump for now. Is there maybe a more efficient way to handle the above type of functionality that I may be missing?

Thanks again,
Norman
Post Reply