Dev-friendly way for Automation Rule snippet development?

Questions about and code samples for automation process code snippets within Select.
Post Reply
toddsou
Posts: 75
Joined: Wed Jul 25, 2012 9:39 am

Dev-friendly way for Automation Rule snippet development?

Post by toddsou »

Hi-

I'm looking to do some Iron Python development to create some code snippets to be used by Automation Processes.

While the SDK provides lots of good info about Custom Order Rules development, including how to launch the Shift-F12 editor, and set breakpoints, etc, I did not see similar guidance for the development and debugging of Automation Process snippets.

Can you refer me to such guidance?

Thank you.
kkellett
Posts: 14
Joined: Thu Sep 25, 2008 8:51 am
Location: Raleigh, NC
Contact:

Re: Dev-friendly way for Automation Rule snippet development?

Post by kkellett »

Hello,

For Automation code snippets that evaluate whether the process should run, if there are issues with them, the Event Viewer will log errors on the Mid-tier server which are usually very helpful. For errors with Action Code snippets, they will be shown in the Automation Monitor.

For debugging, take the code snippet and turn it into a Custom Order Rule (COR) to utilize the breakpoints and debugging mode in the SoftPro Development Studio. Often, simply copying in the code will reveal an indent or ":" that's missing after saving it as a COR. If you're not so luck, a few edits will need to be made to ensure the Context matches your code snippet and that the COR understands the short-hand "Context" that is used in Automation snippets. Here's a starter COR for this purpose:

Code: Select all

"""
Add the "guts" of your Auto code snippet (not the def line or closing function name)
and use the RaiseInformation aspect to test out a Code snippet. 
"""
def Order_RelatedOrders_Validate(args):
	Context = args.Context   
	args.RaiseInformation('You found ' + str(Context))
Here's an example of taking an Automation Code Snippet and changing it to work as a COR. Original Auto code snippet (runs under Order has a Contact, so the context is Contact).

Code: Select all

from System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *

# Look for Cell address in all Buyer contacts
# Context is Buyer
def HasBuyerCell():

	# For the Individual's Cell Fields (not using Forwarding fields)
	if Context.BuyerSellerType == 'Male' or Context.BuyerSellerType == 'Female' or Context.BuyerSellerType == 'Joint':
		if Context.Individual1.Cell or Context.Individual2.Cell:
			return True
	# For People (if Organization)
	for person in Context.People:
		if person.Cell:
			return True

HasBuyerCell()
Below is after editing to comment the Auto code snippet's function name and closing function and giving it a def line of "def Buyer_Name_Validate(args):" so that this will run on the same context as the Auto code snippet. Here, we have replaced the "return True" lines with args.RaiseInformation so that we will receive Information in the Order when the conditions are true.

Code: Select all

from System import *
from SoftPro.ClientModel import *
from SoftPro.Select.Client import *

# Look for Cell address in all Buyer contacts
# Context is Buyer
#def HasBuyerCell():
def Buyer_Name_Validate(args):
	Context = args.Context
	# For the Individual's Cell Fields (not using Forwarding fields)
	if Context.BuyerSellerType == 'Male' or Context.BuyerSellerType == 'Female' or Context.BuyerSellerType == 'Joint':
		if Context.Individual1.Cell or Context.Individual2.Cell:
			args.RaiseInformation('Code would return True for line 13 - an Individual Person has a Cell number. ' + str(Context.Name))
			#return True
			
	# For People (if Organization)
	for person in Context.People:
		if person.Cell:
			args.RaiseInformation('Code would return True for line 17 - an Org Person has a Cell number. ' + str(Context.Name))
			#return True

#HasBuyerCell()
Post Reply