Validation Rule

Questions about and code samples for custom order rules and validation within Select.
Post Reply
kylecrosland
Posts: 7
Joined: Thu May 04, 2017 6:28 pm

Validation Rule

Post by kylecrosland » Wed Oct 16, 2019 12:59 pm

Hello,

I'm trying to create a rule that will throw up an error message, if the payoff request good through date is before the settlement date. What am I doing wrong? Thanks!

Code: Select all

def WarnIfPayoffExpiresBeforeSettlementDate(args):
	order = args.Context.Root
	lenders = order.PayoffLenders
	for l in lenders:
		#args.Value = order.SettlementDate.Date()
			expDate = IOrderItem.GetProperty(l, 'PayoffRequestPayoffGoodThroughDate_SP#')
			if str(expDate) != '(None)':
				if order.SettlementDate > expDate:
					args.RaiseError("Payoff will expire prior to closing!")
				
#rename rule
WarnIfPayoffExpiresBeforeSettlementDate.__name__ = 'PayoffLender_PayoffRequestPayoffGoodThroughDate_SP#_Validate'

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

Re: Validation Rule

Post by BobRichards » Wed Oct 16, 2019 4:38 pm

What does it do when you run the code? What debugging have you done?
Bob Richards, Software Developer, SoftPro

kylecrosland
Posts: 7
Joined: Thu May 04, 2017 6:28 pm

Re: Validation Rule

Post by kylecrosland » Wed Oct 16, 2019 5:37 pm

There are two issues.

1.) When nothing is entered into the Payoff-Good-Through field, my custom error message is displayed. This is not the behavior I want. I don't want to see the error message unless a date is entered into the field AND that date falls before the settlement date.

2.) When a date is entered into the field, I see "Error encountered during rule execution. expected Date, got DateTime." I guess the settlement date field is a DateTime, and the Payoff Good Through field is just a date field, and it doesn't like comparing the two as-is.

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

Re: Validation Rule

Post by BobRichards » Thu Oct 17, 2019 10:35 am

I fixed the Date/DateTime type issue by explicitly converting them to the same type in the inequality comparison. You can ask a Date for a DateTime object by using the Convert.ToDateTime().

The second item I changed is a performance enhancement showing the Pythonic way to do things. The preferred way to test against None is to say "if x is None" or "if x is not None". It is much faster since you don't have to convert "x" to a string then do a string comparison and reads like English when degbugging your code.

Code: Select all

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

def WarnIfPayoffExpiresBeforeSettlementDate(args):
	order = args.Context.Root
	lenders = order.PayoffLenders
	for l in lenders:
		expDate = IOrderItem.GetProperty(l, 'PayoffRequestPayoffGoodThroughDate_SP#')
		if expDate is not None:
			if order.SettlementDate > Convert.ToDateTime(expDate):
				args.RaiseError("Payoff will expire prior to closing!")
				
#rename rule
WarnIfPayoffExpiresBeforeSettlementDate.__name__ = 'PayoffLender_PayoffRequestPayoffGoodThroughDate_SP#_Validate'
Bob Richards, Software Developer, SoftPro

kylecrosland
Posts: 7
Joined: Thu May 04, 2017 6:28 pm

Re: Validation Rule

Post by kylecrosland » Thu Oct 31, 2019 10:10 am

Perfect! Thanks, Bob! :-)

Post Reply