Page 1 of 1

Enforce rule on Marketing Source in Order Contacts

Posted: Tue Nov 13, 2012 3:03 pm
by kqian
Hi,

I'd like to know if there is a way to enforce that there must be ONE Marketing Source specified in the Order Contact list for a ProForm order.
In our case, users sometime mistakenly delete the Marketing Source or add more than one MS. We want to constrain that there need to be one MS when user edit the order and save.

Thanks.

Kevin

Re: Enforce rule on Marketing Source in Order Contacts

Posted: Tue Nov 13, 2012 4:41 pm
by john.morton
In our next major release of Select, we're going to add the ability to tie into the OrderSaving event in server side code so that you can enforce any custom save validations you might need.

Re: Enforce rule on Marketing Source in Order Contacts

Posted: Wed Apr 15, 2015 9:40 am
by John Morris
This can also be done using "custom order rules" written using an order module (i.e. IronPython). This is ability is covered in the SDK documentation. The rule looks like this:

Code: Select all

def Order_Contacts_Validate(args):
  count = 0

  for c in args.Context.Contacts:
    if c.IsMarketingSource:
      count = count + 1

  if count == 0:
    args.RaiseError("Order must contain a marketing source.")

  if count > 1:
    args.RaiseError("Only one marketing source should be marked.")

Re: Enforce rule on Marketing Source in Order Contacts

Posted: Wed Apr 15, 2015 11:24 am
by mwalsh
I'm trying to do something similar to the Proform custom validation code that is detailed in this thread, but based on ContactType of Other Contacts. I'm using "if c.ContactType == 'CLIENT':" as my condition, but it's not catching the use case.

1.) Am I not accessing the ContactType value correctly?
2.) When I right click on Order in the project explorer, I don't have an option to "Set Global Default Rule", I get “Set as Default Order". Are they the same?

I'm using:
def Order_Contacts_Validate(args):
count = 0
for c in args.Context.Contacts:
if c.ContactType == 'CLIENT':
count = count + 1
if count > 1:
args.RaiseError("Custom Validation (Code OC001)! More than 1 'Client' contact type listed.")

Re: Enforce rule on Marketing Source in Order Contacts

Posted: Wed Apr 15, 2015 3:10 pm
by BobRichards
If what you meant by a "Client" is "Others" contact types, this examples shows a quick way to get the number of items in a collection.

Code: Select all

def Order_Contacts_Validate(args):
	
	# Make sure Others collection exists before continuing
	if args.Context.Others is None:
		return
	
	# Can use "Count" to get total number of contacts in specific Contact type.
	if args.Context.Others.Count > 0:
		args.RaiseWarning("Custom Validation (Code OC001)! More than 1 'Other' contact type listed.")
And yes - “Set as Default Order" is the same as "Set Global Default Rule".