10/05/2010

Accessing Contractor Data from Fire Permit Screen

I had a request from a Fire Module customer who wanted to be able to add Contractor information to a Fire Permit record in a similar fashion used by the Building or Zoning screens. The following script will pull up a browse table of all Contractor names and then place the selected name and license number in the Fire Permit screen User3 field. It uses the left-click option of the User Script button. In the User Scripts screen I added a new item using "Fire" for the Module, "Fireperm" for the Screen, and "Left" for the Action:

if fire2screen.isediting
select alltrim(trim(first_name)+" "+last_name) as name, license;
from contract into cursor tempcont
on key label enter keyboard chr(23)
on key label spacebar keyboard chr(23)
on key label rightmouse keyboard chr(23)
browse normal in window mainzone noedit nodelete;
title "Contractor Records - Press Space Bar to Select"
if lastkey() = 23
replace fireperm.user3 with trim(tempcont.name)+" "+tempcont.license
fire2screen.zp_pageframe1.page2.refresh
endif
on key label spacebar
on key label rightmouse
on key label enter
fire2screen.show
use in iif(used("tempcont"),"tempcont",0)
select fireperm
endif

This is an unusual script request but it illustrates how powerful the scripting option can be.

9/01/2010

Linking to Web Geocoding Options in ZP SQL

For ZonePro SQL there are some great mapping and geocoding options available in the Staff web site interface that are not available in the Windows interface. But, you can use a script to launch the key web page directly from the Property Screen in the Windows interface. Then you can use the web site to map the property, find and tag neighboring properties, or get driving directions. This script works great from either the Internet Link button or the User Script button. For this example we'll use the right-click option of the User Script button. In the User Scripts screen we added a new item using "Base" for the Module, "Property" for the Screen, and "Right" for the Action:

GoURL("http://www.zpdemo.zpuser.com/work/geocode/geomain.aspx?passedid="+property.prop_id)

Note that this script is for the ZP Demo web site. You would of course change that part of the URL to point to your own web site.

4/29/2010

Setting Dual Deadlines for Expire Dates

I just had a customer ask about another Expire Date scenario. They don't have sliding Expire Dates but they have two deadlines. All permits expire in six months if construction is not started, but once started they have two years to finish. To keep track of this scenario you can use the same tutorials that go with the sliding Expire Dates with just some minor modifications to the initial script. Basically you set up the initial six month expiration deadline by setting Expire Days to 183 for each permit type in Maintenance. Then you only need a script to make the switch to the two year deadline. This is done with a script that uses "Building" as the Module, "Building" as the Screen, and "Close" as the Action.

myanswer = 0
mycode = id_code
select max(last_insp) from detail1;
where detail1.id_code = mycode into array mydate
mylast = mydate(1)
if not empty(mylast) and mylast > (cert_date)
myanswer = messagebox("New expire should be "+dtoc(cert_date +730);
+chr(13)+"Do you want to fix it?",68,"New Expiration Needed")
endif
use in detail1
if myanswer = 6
proceedwithclose = .F.
replace exp_date with cert_date+730
buildscreen.isediting = .T.
buildscreen.refresh
endif

4/15/2010

Sliding Expiration Dates

Bradford County wants to institute a policy of always setting the Expire Date six months out from the last completed inspection for a building permit. The idea being that this would make it easy to run a report at any time using the Expire Date to find out which permits were in danger of expiring because of no activity in six months. The script below was designed for the "Close" button option of the Building database. It checks to find the most recent Last Inspection date in the Inspection Details database and then compares that with the current Expire Date. If the gap is less than six months it displays a message saying that the Expire Date should be changed and lists the date it should be changed too. This script uses "Building" as the Module, "Building" as the Screen, and "Close" as the Action.

myanswer = 0
mycode = id_code
select max(last_insp) from detail1;
where detail1.id_code = mycode into array mydate
mylast = mydate(1)
if not empty(mylast) and mylast > (exp_date - 183)
myanswer = messagebox("Last inspection was "+dtoc(mylast);
+chr(13)+"New expire should be "+dtoc(mylast +183);
+chr(13)+"Do you want to fix it?",68,"New Expiration Needed")
endif
use in detail1
if myanswer = 6
proceedwithclose = .F.
replace exp_date with mylast+183
buildscreen.isediting = .T.
buildscreen.refresh
endif

There are Sliding Expire Date tutorials in the Tutorial section of our web site for both ZP 32 and ZP SQL. These tutorials cover this topic at much greater length.

Create Copies of Database for use with ArcView

A customer wanted to know how to access ZonePro databases from ArcView. I explained how ArcView chokes on Notes fields and how the ZP Copy program can be used to make copies of the databases minus the fields that ArcView can't handle. The ZP Copy program is really just another way of running scripts and you can do the same thing directly within ZonePro. By way of a demonstration, I wrote a script that runs from the Script button on the Main Screen that makes a copy of the Property database minus the Notes fields. You can then link ArcView to the "property_copy" database. This script uses "Base" as the Module, "MainScreen" as the Screen, and "Right" as the Action.

if file("property.dbf")
use property in 0
select property
copy to property_copy fields except note* fox2x
wait window "Copy Made" nowait
use in property

Note that this script only works with ZP 32.

Link Photos for Contractor Database

The City of Whiting wanted to know if they could use the Photo Module to attach image files to records in the Contractor Screen. While that is not possible, I did devise a script that gives some of the same functionality. This script looks in a designated folder to see if there is a subfolder that matches the name of the contractor company. If it finds such a folder it launches the folder in Windows Explorer. The user can then easily see the contents of the folder be they image files, Word documents, or whatever. Using the Windows thumbnail option with such folders makes them even more informative. While this script uses the Company field as the folder name, almost any field in the contractor database could be used as the matching criteria. This script works well with one of the
Script Button options such as "Left" or "Right". It's worth noting that this script would work just as well in the Property Screen as a poor man's substitute for Photo Module. This script uses the "Contractor" Module, the "Contractor" Screen and the "Left" Action.

myfolder = "c:\photos\" + trim(company)
if directory(myfolder)
shellexecute(0,"open",myfolder,"","",1)
else
wait window "Cannot Find Folder" nowait
endif

Forcing a Field Value Entry

In the Town of Swansboro they want to keep track of both a calculated job cost and the estimated job cost for any building permits. The calculated job cost is used to derive the permit fee and is stored in the Job Cost field. The estimated job cost is provided by the applicant and is stored in the User5 field. Because the estimated job cost is stored on the extra tab, they want to make sure they don't forget to enter it. This script won't allow you to save the record is that field is blank. The script uses "Building" as the Module, "Building" as the Screen and "Save" as the Action:

 if empty(build1.user5)
= messagebox("Estimated Job Cost field is empty!", 16, "Missing Info")
proceedwithsave = .F. 
endif

Notice that the third line makes use of a special script variable "proceedwithsave" to prevent the Save operation from continuing. If you wanted to give a warning but still allow the Save you could emit that line.