Using Type Fields

Discussions related to writing and managing custom business rules.

Moderator: Phil Barton

Post Reply
kkellett
Posts: 14
Joined: Thu Sep 25, 2008 8:51 am
Location: Raleigh, NC
Contact:

Using Type Fields

Post by kkellett »

I'm attempting a simple rule that Validates the Order Type when the Transaction Type is Purchase. The hotspot needs to be on the Order Type field. I suspect that the field "Type" being "IOrderType" means I need to code this field differently. On the 3rd to last line below, I believe I've correctly converted the Order Type field to a string and then checked to see if it's blank. Still, the rule isn't running. Unsure if my code is wrong elsewhere or if the def line has to be written differently to hotspot to the Order Type field. It does appear that the forum is not holding indents and I cannot attach a text file.

from System import *
from SoftPro.ClientModel import *
from SoftPro.OrderTracking.Client import *
from SoftPro.OrderTracking.Client.Orders import *

# Edit the message below if you want to change the message.
NoOrderType = 'Purchase Transactions require an Order Type.'

##############################################################################
#
# Rule file name: 150-412_ValidateOrderType.txt
#
# If Transaction Type is Purchase, validate that something is chosen in the Order Type drop-down
# Fires on 2nd save
# Ignores Templates
#
# Version
# 1: Original
#
##############################################################################


#Set Hotspot to the Order Type field
def Order_Type_Validate(args):
order = args.Context.Root

# Exit if this is a template.
if order.IsTemplate:
return

# Ignore rule until 2nd order save.
if order.Identifier.Version < 2:
return

# Ignore rule if the Transaction type is something besides Purchase
if order.TransactionType != TransactionType.Purchase:
return

# On Purchase Transactions, Raise Error if the Order Type is Blank
OrderType = str(order.Type)
if OrderType is None:
args.RaiseError(NoOrderType)
kkellett
Posts: 14
Joined: Thu Sep 25, 2008 8:51 am
Location: Raleigh, NC
Contact:

Re: Using Type Fields

Post by kkellett »

Thanks to Dan Chapin for finding the issue in this rule. Simply had the coding wrong for IF the Order Type if blank:

from System import *
from SoftPro.ClientModel import *
from SoftPro.OrderTracking.Client import *
from SoftPro.OrderTracking.Client.Orders import *

# Edit the message below if you want to change the message.
NoOrderType = 'Purchase Transactions require an Order Type.'

##############################################################################
#
# Rule file name: 150-412_ValidateOrderType.txt
#
# If Transaction Type is Purchase, validate that something is chosen in the Order Type drop-down
# Fires on 2nd save
# Ignores Templates
#
# Version
# 1: Original
#
##############################################################################


#Set Hotspot to the Order Type field
def Order_Type_Validate(args):
order = args.Context.Root

# Exit if this is a template.
if order.IsTemplate:
return

# Ignore rule until 2nd order save.
if order.Identifier.Version < 2:
return

# Ignore rule if the Transaction type is something besides Purchase
if order.TransactionType != TransactionType.Purchase:
return

# On Purchase Transactions, Raise Error if the Order Type is Blank
OrderType = str(order.Type)
#args.RaiseError(OrderType)
if OrderType is '':
args.RaiseError(NoOrderType)
Post Reply