Need Help with Validation Rule

Questions about and code samples for custom order rules and validation within Select.
Post Reply
slind
Posts: 8
Joined: Thu Nov 13, 2008 1:59 am
Location: Cincinnati, Ohio

Need Help with Validation Rule

Post by slind »

I am new to Iron Python (I have not created anything yet).

I would like to create a validation check on the underwriter by lender and would appreciate any help you can give me.

Example:

If ({{Order.Lenders[1].LookupCode}}="ABC" and {{Order.Underwriters[1].LookupCode}}<>"OR") Then
"The Underwriter for ABC Bank should be Old Republic"
EndIf

Thanks!
Stephanie
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Need Help with Validation Rule

Post by BobRichards »

It is most unfortunate that we have not provided much information to date on how to use Custom Order Rules (CORs). Be aware that the syntax is very different from the Select Formula language since is uses - well - Python.

Since Lender is the context in this Validate rule, Select will call this function each for each lender in the order. If there is a lender with a lookup code of "ABC" we will eventually go past the first "if" statement and look at the collection of underwriters. If we find the one with a lookup code of "OR" then we will just exit. However, if we don't find it, we will display your warning for the user in the Errors and Warnings window using the RaiseWarning() method.

Code: Select all

from System import *
from SoftPro.ClientModel import *
from SoftPro.OrderTracking.Client import *
from SoftPro.OrderTracking.Client.Orders import *

def Lender_LookupCode_Validate(args):

	# This is an Lender contact.  If there is no Lookup Code or it is not "ABC" then exit.
	lookupCode = args.Context.LookupCode
	if not lookupCode or lookupCode != 'ABC':
		return
		
	# Convenience variable for later.	
	order = args.Context.Root
	
	# This is the Lender with Lookup Code of "ABC".
	# Now look for the matching underwriter.
	underwriters = (u for u in order.Underwriters if u.LookupCode == 'OR')
	und = next(underwriters, None)
	if und is not None:
		# There is at least one Lookup Code "OR" underwriter in order.  Just exit.
		return
	
	# Lender "ABC" exists without underwriter "OR".  Display a warning.
	args.RaiseWarning('The Underwriter for ABC Bank should be Old Republic')
The "from" statements at the top are always inserted by the SoftPro Development Studio whenever you create a new COR. The tells Python where to find libraries of code. Even though you may not need them all, just leave them in since it will not affect the speed or size to have them. Also the white space at the beginning of each line of text is either one or two tab characters - Python will require consistency when writing code.
Bob Richards, Senior Software Developer, SoftPro
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Need Help with Validation Rule

Post by BobRichards »

If you display a message with "args.RaiseWarning()" like we did in the previous message, the user will be able to ignore the warning and save the order anyway. Be aware that you can also use "args.RaiseError()" instead. This will not only display an error on the Errors and Warnings window, but also prevent the user from saving the order without fixing the problem.

I'm just letting you know about this option in case you run into cases you need to prevent the user from doing something egregious.
Bob Richards, Senior Software Developer, SoftPro
slind
Posts: 8
Joined: Thu Nov 13, 2008 1:59 am
Location: Cincinnati, Ohio

Re: Need Help with Validation Rule

Post by slind »

Thank you very much! I appreciate you helping me. I'm going to take an online Iron Python course so hopefully that will help me with COR.
Post Reply