Enforce rule on Marketing Source in Order Contacts

Discussions related to writing and managing custom business rules.

Moderator: Phil Barton

Post Reply
kqian
Posts: 68
Joined: Wed Feb 23, 2011 4:01 pm

Enforce rule on Marketing Source in Order Contacts

Post 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
john.morton
Posts: 89
Joined: Wed Nov 16, 2011 11:51 am

Re: Enforce rule on Marketing Source in Order Contacts

Post 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.
John Morris
Posts: 411
Joined: Thu Sep 11, 2008 11:35 am
Location: Raleigh, NC, USA
Contact:

Re: Enforce rule on Marketing Source in Order Contacts

Post 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.")
John Morris
Sr. Software Architect
SoftPro
mwalsh
Posts: 10
Joined: Wed Apr 15, 2015 8:49 am

Re: Enforce rule on Marketing Source in Order Contacts

Post 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.")
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Enforce rule on Marketing Source in Order Contacts

Post 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".
Bob Richards, Senior Software Developer, SoftPro
Post Reply