Page 1 of 1

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

Posted: Wed Nov 01, 2023 3:47 pm
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"

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

Posted: Thu Nov 02, 2023 2:52 pm
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.

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

Posted: Fri Nov 03, 2023 10:02 am
by svilla
This is perfect! Thank you so much for your help.