Validation Rule

Questions about and code samples for custom order rules and validation within Select.
Post Reply
kylecrosland
Posts: 12
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: 1057
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: 12
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: 1057
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: 12
Joined: Thu May 04, 2017 6:28 pm

Re: Validation Rule

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

Perfect! Thanks, Bob! :-)

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

Re: Validation Rule

Post by kylecrosland » Tue Oct 27, 2020 9:27 am

Hi Bob,

When we built this originally, I used a custom field for the payoff expiration date. I'd like to modify it, so that it references any of the canned payoff expiration dates used in the settlement statement.

My issue is: I'm having a tough time referencing those fields. In the HUD, the field is {{Order.HUDs.Section500.Charges.Calculation.ExpireOnDate}}. In the CD, I don't know the name of the field. The Field Code Browser doesn't tell me. What context and field should I use for my validation rule?

Thanks!

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

Re: Validation Rule

Post by BobRichards » Tue Oct 27, 2020 10:42 am

We do have a neat trick to help you get more information about any field. I created a CDF order, went to a section N charge and put my cursor in the "Payoff expires on" field box. The magic occurs when you press Alt+F6.
2020-10-22_15-33-44.png
2020-10-22_15-33-44.png (22.74 KiB) Viewed 1005 times
This triggers a popup where you see all the information that would be in the bottom panel of the Field Code Browser. Your custom order rule would be:

Code: Select all

def Payoff_ExpireOnDate_Value:
    ...
Bob Richards, Software Developer, SoftPro

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

Re: Validation Rule

Post by kylecrosland » Wed Oct 28, 2020 12:38 pm

Thanks again, Bob. Any idea why this isn't working?

Code: Select all

def Payoff_ExpireOnDate_Validate(args):
	order = args.Context.Root
	disbDate = order.DisbursementDate
	if (disbDate is not None) and (args.Value is not None):
		if disbDate >= args.Value:
			args.RaiseWarning('The payoff is set to expire on or before disbursement.')

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

Re: Validation Rule

Post by BobRichards » Fri Oct 30, 2020 1:38 pm

So there were two problems with the COR. One was mine and the other was yours. :-)

The original name of the function shows up as underlined in blue in SoftPro Developer Studio - this means that the name meets the simple criteria to be a COR but Select can't match it up to available contexts and properties. The method I gave you (Alt+F6) typically works but here it doesn't - and frankly there is no easy way for you to determine what it is in this case. But believe me - this is one of the rare exceptions!

The other mistake was that the current value for the context expiration date is not "args.Value" but "args.Context.ExpireOnDate".

Code: Select all

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

def CDFPayoffChargeCalculation_ExpireOnDate_Validate(args):
    order = args.Context.Root
    disbDate = order.DisbursementDate
    expireOnDate = args.Context.ExpireOnDate
    if (disbDate is not None) and (expireOnDate is not None):
        if disbDate >= expireOnDate:
            args.RaiseWarning('The payoff is set to expire on or before disbursement.')
Bob Richards, Software Developer, SoftPro

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

Re: Validation Rule

Post by kylecrosland » Tue Nov 03, 2020 5:52 pm

Thanks, Bob! :D

Post Reply