Page 1 of 1

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

Posted: Thu Jun 15, 2023 2:17 pm
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?

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

Posted: Thu Jun 15, 2023 4:12 pm
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.

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

Posted: Fri Jun 16, 2023 11:56 am
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.

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

Posted: Fri Jun 16, 2023 1:49 pm
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

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

Posted: Mon Jun 19, 2023 10:28 am
by aottilo
Perfect!! I completely understand. Thank you so much for your help! I am going to reorganize.