First time using a Custom Fields in a Code Snippet

Questions about and code samples for automation process code snippets within Select.
Post Reply
B_Hinote
Posts: 41
Joined: Tue Jan 08, 2019 7:20 pm

First time using a Custom Fields in a Code Snippet

Post by B_Hinote » Thu Mar 21, 2019 6:31 pm

I am creating a Code Snippet that needs to check the value of a Custom Field, which I have added to several of the Order Contact Types. However, the editor is interpreting the "#" as the start of a comment rather than the balance of the code.

Code: Select all

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

def CreateTask
	#Return True if PreTSG Task exists or (TypingTSG exists and the Order is not for a Pre-Tsg Servicer)
	isPreTSG = False	# Defaulted to False
	if (any(c.Flueid_PreTSGServicer## == True for c in Order.Contacts)):
		isPreTSG = True	# Set to True when one of the Contact has the Pre-TSG Servicer Flag set to True.

	# Return True if the Task Code is Not Empty and is either PreTSG or (TypingTSG and Not a Pre-TSG Servicer Order)
	If any((task.Code is not None and (task.Code.lower() == 'pretsg' or (task.Code.lower() == 'typingtsg' and isPreTSG == False))) for task in Context.Tasks):
		Return True

CreateTask()
What do I need to change to get the custom field recognized as a field rather than a comment?
Any help in resolving this issue would be greatly appreciated.

Thank you

B_Hinote
Posts: 41
Joined: Tue Jan 08, 2019 7:20 pm

Re: First time using a Custom Fields in a Code Snippet

Post by B_Hinote » Thu Mar 21, 2019 11:18 pm

Ok, I made advancements on how to incorporate a custom field, however now I am running into an issue using the overall Context "Contacts" as opposed to a specific Context like "MortgageBrokers". I suspect this is because the custom field has not been defined on every Contact Type, but there are 10 of them that do which is why I am trying to use the overall Context of "Contacts". How can I use "Contacts" and condition against those Contact Types that do not include the Custom Field.

My latest code is as follows:

Code: Select all

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

def AddTask():
	isPreTSGServicer = False
	#for con in Context.MortgageBrokers:  #Works when I use this, as the Custom Field has been defined on the MortgageBrokers Context.
	for con in Context.Contacts:	#Errors Out when I use "Contacts".  I suspect this is because Not All Contacts have the Custom Fields.
		PreTSGServicer = IOrderItem.GetProperty(con, 'PreTSGServicer##')
		if PreTSGServicer is not None and PreTSGServicer == True:
			isPreTSGServicer = True
			
	if any((task.Code.lower() == 'pretsg' or (task.Code.lower() == 'typingtsg' and isPreTSGServicer == False)) for task in Context.Tasks):
		return True
			
AddTask()

BobRichards
Posts: 1057
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: First time using a Custom Fields in a Code Snippet

Post by BobRichards » Fri Mar 22, 2019 9:58 am

You can ask an IOrderItem if it has a property (custom or otherwise) with HasProperty().

Code: Select all

for con in Context.Contacts:
    if IOrderItem.HasProperty(con, 'PreTSGServicer##'):   # Does this contact have the custom propery?
        # Yes - it does.
        PreTSGServicer = IOrderItem.GetProperty(con, 'PreTSGServicer##')
We use this frequently if we don't know the specific object type we are passed.
Bob Richards, Software Developer, SoftPro

B_Hinote
Posts: 41
Joined: Tue Jan 08, 2019 7:20 pm

Re: First time using a Custom Fields in a Code Snippet

Post by B_Hinote » Fri Mar 22, 2019 1:56 pm

That did the trick and resolved the issue.

Thank you for your time and efforts.

Post Reply