Looping through Commitment Exceptions looking for text

Questions about and code samples for custom order rules and validation within Select.
Post Reply
DanChapin
Posts: 16
Joined: Thu Sep 24, 2015 10:40 am

Looping through Commitment Exceptions looking for text

Post by DanChapin »

Hi Everyone,

I am trying to loop through the commitment[1] exceptions in an order and search the text of the exception for a specific string. "24+ Year Title Chain" when/if it is found, I want to grab the entire exception text to place a copy in another field.

Does anyone have any ideas to get me started?

Thanks
Dan
danvanf
Posts: 54
Joined: Fri Nov 07, 2008 10:45 am
Location: Dayton, Ohio
Contact:

Re: Looping through Commitment Exceptions looking for text

Post by danvanf »

Hey Dan,

I can get you started, not quite complete. I hooked int Escrow Brief Legal, any scrollable field should work.

Code: Select all

def Property_EscrowBriefLegal_Value(args):
	root = args.Context.Root
	sav = ''
	for co in root.Title.Commitments:
		for t in co.Exceptions:
			if (t.Text.Contains('24+ Year Title Chain')):
		 		sav = t.Text
		 		break
	args.Value = sav 
The issue I ended up with is the output text is RTF.

There is a rather interesting looking extension in SoftPro.Select.Controls.StringExtentions called ToPlainText, thus far I've been unable to use it. So I'll pass it off to the next typist.

-Dan
I blog at http://DanVanFleet.com on SoftPro and other things
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Looping through Commitment Exceptions looking for text

Post by BobRichards »

Please don't use any objects in the SoftPro.Select.Controls namespace in Custom Order Rules! It will create execution errors since these libraries don't exist on the mid-tier and the orders are opened by mid-tiers.
Bob Richards, Senior Software Developer, SoftPro
danvanf
Posts: 54
Joined: Fri Nov 07, 2008 10:45 am
Location: Dayton, Ohio
Contact:

Re: Looping through Commitment Exceptions looking for text

Post by danvanf »

Excellent thanks, as you noted the DLL doesn't import which was the show stopper. I was RTFM... sometimes giving the uneducated a manual isn't the best course of action. ;)

The RTF issue remains, but I may have found a solution with the help of https://gist.github.com/gilsondev/7c1d2 ... 11cfb08676. Bob, Does this pass muster? Dan, It doesn't deal with multiples properly, but it doesn't sound like you're going to care. (it also doesn't break properly, but again it doesn't sound.....)

Here's my play:

Code: Select all

from System import *
from SoftPro.ClientModel import *
from SoftPro.OrderTracking.Client import *
from SoftPro.OrderTracking.Client.Orders import * ;) 
import re

def Property_EscrowBriefLegal_Value(args):
	root = args.Context.Root
	sav = ''
	for co in root.Title.Commitments:
		for t in co.Exceptions:
			if (t.Text.Contains('24+ Year Title Chain')):
		 		sav = t.Text
		 		break
	args.Value = striprtf(sav)

def striprtf(text):
   """
Extract text in RTF Files. Refactored to use with Python 3.x
Source:
    http://stackoverflow.com/a/188877
Code created by Markus Jarderot: http://mizardx.blogspot.com
"""
   pattern = re.compile(r"\\([a-z]{1,32})(-?\d{1,10})?[ ]?|\\'([0-9a-f]{2})|\\([^a-z])|([{}])|[\r\n]+|(.)", re.I)
   # control words which specify a "destionation".
   destinations = frozenset((
      'aftncn','aftnsep','aftnsepc','annotation','atnauthor','atndate','atnicn','atnid',
      'atnparent','atnref','atntime','atrfend','atrfstart','author','background',
      'bkmkend','bkmkstart','blipuid','buptim','category','colorschememapping',
      'colortbl','comment','company','creatim','datafield','datastore','defchp','defpap',
      'do','doccomm','docvar','dptxbxtext','ebcend','ebcstart','factoidname','falt',
      'fchars','ffdeftext','ffentrymcr','ffexitmcr','ffformat','ffhelptext','ffl',
      'ffname','ffstattext','field','file','filetbl','fldinst','fldrslt','fldtype',
      'fname','fontemb','fontfile','fonttbl','footer','footerf','footerl','footerr',
      'footnote','formfield','ftncn','ftnsep','ftnsepc','g','generator','gridtbl',
      'header','headerf','headerl','headerr','hl','hlfr','hlinkbase','hlloc','hlsrc',
      'hsv','htmltag','info','keycode','keywords','latentstyles','lchars','levelnumbers',
      'leveltext','lfolevel','linkval','list','listlevel','listname','listoverride',
      'listoverridetable','listpicture','liststylename','listtable','listtext',
      'lsdlockedexcept','macc','maccPr','mailmerge','maln','malnScr','manager','margPr',
      'mbar','mbarPr','mbaseJc','mbegChr','mborderBox','mborderBoxPr','mbox','mboxPr',
      'mchr','mcount','mctrlPr','md','mdeg','mdegHide','mden','mdiff','mdPr','me',
      'mendChr','meqArr','meqArrPr','mf','mfName','mfPr','mfunc','mfuncPr','mgroupChr',
      'mgroupChrPr','mgrow','mhideBot','mhideLeft','mhideRight','mhideTop','mhtmltag',
      'mlim','mlimloc','mlimlow','mlimlowPr','mlimupp','mlimuppPr','mm','mmaddfieldname',
      'mmath','mmathPict','mmathPr','mmaxdist','mmc','mmcJc','mmconnectstr',
      'mmconnectstrdata','mmcPr','mmcs','mmdatasource','mmheadersource','mmmailsubject',
      'mmodso','mmodsofilter','mmodsofldmpdata','mmodsomappedname','mmodsoname',
      'mmodsorecipdata','mmodsosort','mmodsosrc','mmodsotable','mmodsoudl',
      'mmodsoudldata','mmodsouniquetag','mmPr','mmquery','mmr','mnary','mnaryPr',
      'mnoBreak','mnum','mobjDist','moMath','moMathPara','moMathParaPr','mopEmu',
      'mphant','mphantPr','mplcHide','mpos','mr','mrad','mradPr','mrPr','msepChr',
      'mshow','mshp','msPre','msPrePr','msSub','msSubPr','msSubSup','msSubSupPr','msSup',
      'msSupPr','mstrikeBLTR','mstrikeH','mstrikeTLBR','mstrikeV','msub','msubHide',
      'msup','msupHide','mtransp','mtype','mvertJc','mvfmf','mvfml','mvtof','mvtol',
      'mzeroAsc','mzeroDesc','mzeroWid','nesttableprops','nextfile','nonesttables',
      'objalias','objclass','objdata','object','objname','objsect','objtime','oldcprops',
      'oldpprops','oldsprops','oldtprops','oleclsid','operator','panose','password',
      'passwordhash','pgp','pgptbl','picprop','pict','pn','pnseclvl','pntext','pntxta',
      'pntxtb','printim','private','propname','protend','protstart','protusertbl','pxe',
      'result','revtbl','revtim','rsidtbl','rxe','shp','shpgrp','shpinst',
      'shppict','shprslt','shptxt','sn','sp','staticval','stylesheet','subject','sv',
      'svb','tc','template','themedata','title','txe','ud','upr','userprops',
      'wgrffmtfilter','windowcaption','writereservation','writereservhash','xe','xform',
      'xmlattrname','xmlattrvalue','xmlclose','xmlname','xmlnstbl',
      'xmlopen',
   ))
   # Translation of some special characters.
   specialchars = {
      'par': '\n',
      'sect': '\n\n',
      'page': '\n\n',
      'line': '\n',
      'tab': '\t',
      'emdash': '\u2014',
      'endash': '\u2013',
      'emspace': '\u2003',
      'enspace': '\u2002',
      'qmspace': '\u2005',
      'bullet': '\u2022',
      'lquote': '\u2018',
      'rquote': '\u2019',
      'ldblquote': '\201C',
      'rdblquote': '\u201D',
   }
   stack = []
   ignorable = False       # Whether this group (and all inside it) are "ignorable".
   ucskip = 1              # Number of ASCII characters to skip after a unicode character.
   curskip = 0             # Number of ASCII characters left to skip
   out = []                # Output buffer.
   for match in pattern.finditer(text.decode()):
      word,arg,hex,char,brace,tchar = match.groups()
      if brace:
         curskip = 0
         if brace == '{':
            # Push state
            stack.append((ucskip,ignorable))
         elif brace == '}':
            # Pop state
            ucskip,ignorable = stack.pop()
      elif char: # \x (not a letter)
         curskip = 0
         if char == '~':
            if not ignorable:
                out.append('\xA0')
         elif char in '{}\\':
            if not ignorable:
               out.append(char)
         elif char == '*':
            ignorable = True
      elif word: # \foo
         curskip = 0
         if word in destinations:
            ignorable = True
         elif ignorable:
            pass
         elif word in specialchars:
            out.append(specialchars[word])
         elif word == 'uc':
            ucskip = int(arg)
         elif word == 'u':
            c = int(arg)
            if c < 0: c += 0x10000
            if c > 127: out.append(chr(c)) #NOQA
            else: out.append(chr(c))
            curskip = ucskip
      elif hex: # \'xx
         if curskip > 0:
            curskip -= 1
         elif not ignorable:
            c = int(hex,16)
            if c > 127: out.append(chr(c)) #NOQA
            else: out.append(chr(c))
      elif tchar:
         if curskip > 0:
            curskip -= 1
         elif not ignorable:
            out.append(tchar)
   return ''.join(out)
		
I blog at http://DanVanFleet.com on SoftPro and other things
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: Looping through Commitment Exceptions looking for text

Post by BobRichards »

It looks interesting! Retrieving text from an RTF field has always been a pain. However, I cannot endorse this code on behalf of SoftPro Select since I have no experience with it. Let me know how it goes.
Bob Richards, Senior Software Developer, SoftPro
DanChapin
Posts: 16
Joined: Thu Sep 24, 2015 10:40 am

Re: Looping through Commitment Exceptions looking for text

Post by DanChapin »

Thanks guys. I am going to give this a shot. I already knew about the RTF code and have a RTFCleaner function to deal with that so I will give this all a shot and stop back and let you know how it goes.

Thanks
Again!!
d
Post Reply