COR for Attorney contacts - Need help with def a custom field

Questions about and code samples for custom order rules and validation within Select.
Post Reply
svilla
Posts: 7
Joined: Sat Dec 17, 2022 7:15 pm

COR for Attorney contacts - Need help with def a custom field

Post by svilla »

Hi,
This is the first COR I am trying on my own. By looking at our existing CORs and the devforum I was able to get the code for the first part working. We need an error message if the attorney contact information is missing the "Represents" field.

Now I want to do the same if our custom field AttorneyType## is blank. I am not sure I understand how to define the custom field.

Code: Select all

#	Attorney Contact Missing Data Error 
#	Require Attorney contact to have Represents
#	Require Attorney contact to have an attorney type (Order : Attorney : AttorneyType## custom field)

def Order_Attorneys_Validate(args):
	order = args.Context
	
	# Check every attorney contact and see if the Represents field is not blank
	for attorney in order.Attorneys:
		if attorney.Represents is None or attorney.Represents == "":
			args.RaiseError('Attorney Contact must have data in the Represents field')
			return

def AttorneyType(args):
## ? 

 	# Check every attorney contact and see if the AttorneyType custom field is not blank 
	for attorney in order.Attorneys:
		if AttorneyType is None or AttorneyType == "":
			args.RaiseError("Attorney Type is blank.")
			return

# Redefine custom field
AttorneyType.__name__ = "Attorney_AttorneyType##_Value"
Attachments
Capture.JPG
Capture.JPG (23.15 KiB) Viewed 6934 times
vmrvichin
Posts: 28
Joined: Thu Jul 22, 2021 11:50 am

Re: COR for Attorney contacts - Need help with def a custom field

Post by vmrvichin »

I think this is what you are looking for for the custom field validation.

Code: Select all

def Attorney_AttorneyType_Validate(args):
	#since args.Context is already set to the attorney, just get the custom field
	type = IOrderItem.GetProperty(args.Context, 'AttorneyType##')
	if type is None or type == "":
		args.RaiseError("Attorney Type is blank.")
		return

# Redefine custom field
Attorney_AttorneyType_Validate.__name__ = 'Attorney_AttorneyType##_Validate'
regarding your other validation 'Order_Attorneys_Validate' There is no need to loop through all of the Attorneys if you set it up to look at a specific field on the attorney (in this case Represents), it will still validate on all the Attorneys in the order. This would allow the double clicking on the error message to take you to the specific attorney that is missing the information. As you have it now if a user clicks on the 'Attorney Contact must have data in the Represents field' error they will be taken to the contacts list. So if you had multiple attorneys and only 1 of them was missing the represents field, the user would not know which one. So if you setup your other rule as 'Attorney_Represents_Validate' then double clicking on the error will take you to the specific attorney that is missing the field.
Vlad Mrvichin, Senior Software Developer, Custom Dev, SoftPro
svilla
Posts: 7
Joined: Sat Dec 17, 2022 7:15 pm

Re: COR for Attorney contacts - Need help with def a custom field

Post by svilla »

This is perfect! Thank you so much for your help.
Post Reply