Adding a note to files that have a property address that startswith 0

Questions about and code samples for automation process code snippets within Select.
Post Reply
aottilo
Posts: 7
Joined: Thu Apr 13, 2023 11:00 am

Adding a note to files that have a property address that startswith 0

Post by aottilo »

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

# Get the root order from the context
order = Context.Root

# Check if the address starts with "0"
for prop in Order.Properties:
if prop.Address.Address1.startswith("0"):
# Create a new note
note = Iorder.CreateNew(Context, 'Note')
note.Text = 'Vacant Land Alert'
note.Type = NoteType.Critical
note.DisplayOnOrderOpen = True
Context.Notes.Add(note)




I cannot get it to add the note only on files that the address {{Order.Properties.Address.Address1}} startwith 0
It adds a note to every file or any file that contains a 0 anywhere in the address.

Can someone help me fix my code snippet?
vmrvichin
Posts: 27
Joined: Thu Jul 22, 2021 11:50 am

Re: Adding a note to files that have a property address that startswith 0

Post by vmrvichin »

It seems to be working just fine for me, once I fixed a couple of minor typos in your example. Specifically replacing the capital O with lowercase in the for loop, and capitalizing the O in the Iorder.CreateNew

Code: Select all

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

# Get the root order from the context
order = Context.Root

# Check if the address starts with "0"
for prop in order.Properties:
	if prop.Address.Address1.startswith("0"):
	# Create a new note
		note = IOrder.CreateNew(Context, 'Note')
		note.Text = 'Vacant Land Alert'
		note.Type = NoteType.Critical
		note.DisplayOnOrderOpen = True
		Context.Notes.Add(note)
After that, I tested with the following addresses:
Main 0
0 Main
123 Main

and only the '0 Main' entry triggered the creation of the note.
Vlad Mrvichin, Senior Software Developer, Custom Dev, SoftPro
aottilo
Posts: 7
Joined: Thu Apr 13, 2023 11:00 am

Re: Adding a note to files that have a property address that startswith 0

Post by aottilo »

Thank you for your reply.

Can you try the address like 120 Main Street?

Mine is still triggering when the 0 is anywhere in the number sequence.

Actually, will it run on every file, but just not add the note if it isn't true? Sorry, I am fairly new to code snippets.
vmrvichin
Posts: 27
Joined: Thu Jul 22, 2021 11:50 am

Re: Adding a note to files that have a property address that startswith 0

Post by vmrvichin »

aottilo wrote: Fri Jun 16, 2023 11:56 am Can you try the address like 120 Main Street?
120 Main Street did not create an order note for me.
aottilo wrote: Fri Jun 16, 2023 11:56 am Actually, will it run on every file, but just not add the note if it isn't true? Sorry, I am fairly new to code snippets.
This is correct. Automations trigger based on what you have set in the 'When' section of the Automation Process Wizard. Where do you have this code snippet? If it's all in the Then section, then yes the automation will run every time You can split it up into 2 snippets. The first in the If section to check to see if the property's address starts with a 0, then the Then section could be the one that adds the note. This will then only run the automation when there is a property in the order whos address starts with a 0
Vlad Mrvichin, Senior Software Developer, Custom Dev, SoftPro
aottilo
Posts: 7
Joined: Thu Apr 13, 2023 11:00 am

Re: Adding a note to files that have a property address that startswith 0

Post by aottilo »

Perfect!! I completely understand. Thank you so much for your help! I am going to reorganize.
Post Reply