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 »

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: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Validation Rule

Post by BobRichards »

What does it do when you run the code? What debugging have you done?
Bob Richards, Senior Software Developer, SoftPro
kylecrosland
Posts: 12
Joined: Thu May 04, 2017 6:28 pm

Re: Validation Rule

Post by kylecrosland »

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: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Validation Rule

Post by BobRichards »

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, Senior Software Developer, SoftPro
kylecrosland
Posts: 12
Joined: Thu May 04, 2017 6:28 pm

Re: Validation Rule

Post by kylecrosland »

Perfect! Thanks, Bob! :-)
kylecrosland
Posts: 12
Joined: Thu May 04, 2017 6:28 pm

Re: Validation Rule

Post by kylecrosland »

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: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Validation Rule

Post by BobRichards »

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 6913 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, Senior Software Developer, SoftPro
kylecrosland
Posts: 12
Joined: Thu May 04, 2017 6:28 pm

Re: Validation Rule

Post by kylecrosland »

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: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Validation Rule

Post by BobRichards »

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, Senior Software Developer, SoftPro
kylecrosland
Posts: 12
Joined: Thu May 04, 2017 6:28 pm

Re: Validation Rule

Post by kylecrosland »

Thanks, Bob! :D
Post Reply