Adding a new property triggering

Questions about and code samples for automation process code snippets within Select.
Post Reply
codvisor
Posts: 6
Joined: Wed Nov 09, 2022 12:52 pm

Adding a new property triggering

Post by codvisor »

Hi,
I am trying to achieve the following:
Each time a new property is added and the escrow brief legal field contains the words "special", a new note should appear with the state for that property.
In that case, how can we know that a new property was added? and how can we achieve the above?

Many thanks for your support !!!
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Adding a new property triggering

Post by BobRichards »

Here is an example snippet you can play with. For production, you need to add handling for what if user changes state and other types of potential issues.

The basic plan is to evaluate each property and if it has the word "special" and a valid state, then create a note. To prevent the code from running again, I then add a bit of information that I use as a flag to each property I have handled. Each IOrderItem can store name/value pairs in the Tags dictionary. The users cannot see this collection as it is only accessible by code. Once I create the note, then add a non-empty string to a tag that is unique. (I use guids from online guid generators - that is sufficiently unique).

I used the "Every time and order is saved" and two code snippets. For the "and a code snippet evalutates to true", if I find a property that has not been handled then return "True" so I perform additional operations on it.

Code: Select all

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

# Tag on property when "Then" logic completes work.
PropertyProcessed = '841c887f-eac3-416b-baf0-8ccc3d14025d'

def MyFunc():
    for property in Context.Properties:
        # If property processed then GetTag() will return non-empty string.
        if not IOrderItem.GetTag(property, PropertyProcessed):
            # We found property that has not been processed!
            return True
            
    # All properties have been previously checked for event.
    #   We don't need to do anything else.
    return False

MyFunc()
The additional code ("then do the following: run code snippet") makes sure the criteria are met then creates the note and adds a tag to prevent continuously processing properties.

Code: Select all

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

# Tag on property when "Then" logic completes work.
PropertyProcessed = '841c887f-eac3-416b-baf0-8ccc3d14025d'

for property in Context.Properties:
    if not IOrderItem.GetTag(property, PropertyProcessed):
        # We found property that has not been processed!
        legal = IOrderItem.GetProperty(property, 'EscrowBriefLegal') or ''
        stateName = property.Address.State and property.Address.State.Code
        
        if 'special' in legal.lower() and stateName:
            # Found property with valid state that has keyword in legal brief.
            #   Add note to order with state name.
            note = IOrder.CreateNew(Context, 'Note')
            note.Text = 'Property ' + str(property.Position) + ' is in ' + stateName
            Context.Notes.Add(note)
            
            # Add tag to property to prevent adding another note in the future.
            #    We really don't care what the tag value is - just that it is a non-empty string.
            IOrderItem.SetTag(property, PropertyProcessed, 'dummy text')
Possible Enhancements
  • Instead of saving a dummy string in the tag value, store the state name and in the first code snippet, make sure the tag value matches the current state. If not then the user changed the state. Update as needed.
Bob Richards, Senior Software Developer, SoftPro
Post Reply