Validate Custom Field

Questions about and code samples for custom order rules and validation within Select.
Post Reply
bdutil
Posts: 121
Joined: Tue Jul 19, 2016 1:48 pm

Validate Custom Field

Post by bdutil »

I got most of the way using pieces of other samples but can't seem to get this to fire the Warning. Need the warning to fire if the custom field is not checked Field code in Select is Order.TitleCompanies.OverTheLimit_150431#

Here's what I have so far. Need help in setting the Warning to pull from custom field Order.TitleCompanies.TransactionAmount_150431#.
Also Rep just indicated they'd like it to HotSpot to a Requested Task named Over the Limit Approval if possible. HELP



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

# Edit the message below if you want to change the message.
IsOverTheLimit = 'The total liability amount [INSERT TRANSACTION AMOUNT] is over the limit authorized; please obtain approval, submit the appropriate documentation, and mark the Over the Limit Approval task complete to proceed with the order.'

##############################################################################
#
# Rule file name: 150-431_Validate Over The Limit CF.txt
#
# Validate that Over The Limit Checkbox is marked, if true raise Warning
#
#
# Version
# 1: Original
#
##############################################################################

def TCOverTheLimit_Value(args):

TitleCompany = args.Context

if TitleCompany == None:
# If no TitleCompany Exist - Exit.
return

#Get the Order Context
order = args.Context.Root

#THIS IS THE PART I CAN'T GET TO FIRE.
TCOverTheLimit = IOrder.__getitem__(order, 'TitleCompanies.OverTheLimit_150431#')
if TCOverTheLimit == True:
args.RaiseWarning(IsOverTheLimit)

# Redefine Custom Field Rule names to allow mapping to any field name.
TCOverTheLimit_Value.__name__ = 'TitleCompany_OverTheLimit_150431#_Value'
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Validate Custom Field

Post by BobRichards »

You had two issues with your COR. First is that you can only emit messages (RaiseError, RaiseWarning, RaiseInformation) inside Validate CORs (not Value as it was originally written). Second is that since the context for "OverTheLimit_150431#" is a Contact, you must get the checkbox value from a Contact - not from the Order.

You cannot create a rule for a specific contact type (such as Title Company or Abstractor) - you have to write the rule to accept a Contact and then see if it is the contact type you want. In your case, since you are only creating the custom field on the Title Company, you don't really need to check the contact's type (no other type will generate CORs for this custom field). I added to code to see how you would do this if you were testing a field that existed on multiple contact types but only cared about a single type (such as Marketing source checkbox).

Code: Select all

def TCOverTheLimit_Validate(args):
	contact = args.Context		# Context always exists and never needs to be tested.
	
	# If contact is not a Title Company, then exit.
	#   This is not (strictly speaking) necessary if Title Company is only contact with this custom field.
	if contact.ContactType != ContactType.TitleCompany:
		return
	
	# Get checkbox state from owning Title Company - not the order object.
	TCOverTheLimit = IOrderItem.GetProperty(contact, 'OverTheLimit_150431#')
	if TCOverTheLimit:
		args.RaiseWarning(IsOverTheLimitMessage)
	
# Change COR to map to Custom Field with hash character.
TCOverTheLimit_Validate.__name__ = 'Contact_OverTheLimit_150431#_Validate'
Bob Richards, Senior Software Developer, SoftPro
bdutil
Posts: 121
Joined: Tue Jul 19, 2016 1:48 pm

Re: Validate Custom Field

Post by bdutil »

Thank you that worked.

The other two questions were can I put the value of a custom field in the Warning Message? If so how would that look.
IsOverTheLimitMessage = 'The total liability amount CUSTOM FIELD TitleCompany.TransactionAmount_150431# GOES HERE is over the limit authorized; please obtain approval, submit the appropriate documentation, and mark the Over the Limit Approval task complete to proceed with the order.'

Also can the rule hotspot to a task with a specific name instead of the check box?
Post Reply