Code Snippet for Loan Policy Number & Issued Date

Questions about and code samples for automation process code snippets within Select.
Post Reply
bthorson
Posts: 8
Joined: Wed Feb 21, 2018 1:12 pm

Code Snippet for Loan Policy Number & Issued Date

Post by bthorson »

I would like to create an automation so that if the loan policy number field {{Order.Title.TitleInsuranceCalculations[1].LoanPolicy.Number}} on the Policy Schedule A screen is filled in, the {{Order.Title.TitleInsuranceCalculations.LoanPolicy.IssuedDate}} field will have the system date populate.

I can paste this formula into the Loan Policy issued date and it works.

If (not isempty ({{Order.Title.TitleInsuranceCalculations[1].LoanPolicy.Number}}) ) Then
Value = systemdate()
EndIf

I need help on converting this to a code snippet.

Please let me know if you can assist.

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

Re: Code Snippet for Loan Policy Number & Issued Date

Post by BobRichards »

Create a new Automation Process where "Every time" an order is saved and a "code snippet" evaluates to true then do the following: run "code snippet".

The first code snippet (Condition) returns True if the first loan policy doesn't have a number:

Code: Select all

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

def MyFunc():
	# If there is no Loan Policy, return False
	tic = Context.Title.TitleInsuranceCalculations[0]
	if tic.LoanPolicy is None:
		return False
	
	# If the policy number is None or empty, return True
	num = tic.LoanPolicy.Number
	return num is None or len(num) == 0

MyFunc()
And the second code snippet (Action) set the policy Number field:

Code: Select all

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

# No value in Loan Policy number. Set it to current date.
tic = Context.Title.TitleInsuranceCalculations[0]
tic.LoanPolicy.Number = str(DateTime.Today)
Bob Richards, Senior Software Developer, SoftPro
Kolinski
Posts: 12
Joined: Sat Oct 20, 2018 12:21 am

Re: Code Snippet for Loan Policy Number & Issued Date

Post by Kolinski »

Hello,

I also need this code snippet but I don't believe it does what it was intended to do. This process puts a date into the {{Order.Title.TitleInsuranceCalculations.LoanPolicy.Number}} field if that field is blank. I and the original poster were looking to add the date to the {{Order.Title.TitleInsuranceCalculations.LoanPolicy.IssuedDate}} field when the {{Order.Title.TitleInsuranceCalculations.LoanPolicy.Number}} field is populated for the first time.

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

Re: Code Snippet for Loan Policy Number & Issued Date

Post by BobRichards »

Here are the changes (I'm doing it from memory so you may have to tinker with it).

Condition

Code: Select all

...
	# If the policy issue date has never been set, return True
	date = tic.LoanPolicy.IssuedDate
	return date is None
...
Action

Code: Select all

...
# Select dates are always UTC. Take today's day and convert it to UTC so it will display on UI as "12:00 AM".
tic.LoanPolicy.IssuedDate = DateTime.Now.Date.ToUniversalTime()
Bob Richards, Senior Software Developer, SoftPro
Post Reply