3/22/2010

Linking Zoning Permits To A Building Permit

This script was designed to enable a customer to keep better tabs on permits in other databases that are somehow associated with a given building permit. The example used here is a Zoning permit that is a required precursor to a Building permit. The objective is to be able to view the details of that Zoning permit from within the Building Screen. I created a script that will browse select fields of the Zoning record from within the Building Screen. This script uses "Building" as the Module, "Building" as the Screen and "Left" as the Action which means it will run when you click on the User Script Button in the Building Screen.

mylink = strextract(build1.notes1,"<BeginLink>","<EndLink>",1,1)
if not empty(mylink) select id_code as id,typeinsp as type,details,cert as permit,cert_date as date from zoning
into cursor tempzoning where id_code = mylink
browse normal in window mainzone noedit nodelete title "Linked Zoning Record"
use in iif(used('zoning'),'zoning',0)
use in iif(used('tempzoning'),'tempzoning',0)
endif
select build1

This script will now display a browse window anytime a Zoning record is linked to a Building record, but you have to define that link. To create a link to the desired Zoning permit in the Notes1 field of the Building record I’m using the technique that is explained in the "Selective Notes Printing 1" video on the Training Videos  section of our web page.

Here are the steps I take:
- Go to the Zoning permit record that you want to link and make a note of the ID Code. (That is the second number in the ID string at the top right of the Main tab.)
- Go to the Building record where you want to implement the link.
- Go to the Notes tab. Hit "Edit", and add this text anywhere in the Notes1 field:

<BeginLink> id_code <EndLink>

- Replace the bit that says id_code with the Zoning id_code you made a note of and save your change.

Now you click on the User Script Button to display a browse table with details about the linked Zoning record. This script technique can be expanded to work with any databases. The link tags are good candidates for using with the Notekeeper feature.

To use this option with ZP SQL the initial script needs some minor changes:

mylink = strextract(build1.notes1,"<BeginLink>","<EndLink>",1,1)
if not empty(mylink)
myCommand=[select id_code as id,typeinsp as type,details,cert as permit,;
cert_date as date from zoning where id_code = '] + mylink +[']
dosqlcommand(myCommand,'tempzoning')
browse normal in window mainzone noedit nodelete title "Linked Zoning Record"
use in iif(used('tempzoning'),'tempzoning',0)
endif
select build1

Enhancing Security For Closed Permits

A customer who uses the Security Module wanted a way to prevent users without the proper access levels from editing building permit records after they had been closed. Only users with a security level of 1 should be allowed to edit those permits. The following script assumes that the Occupy Date field is used to indicate whether a record is closed or not. This script uses "Building" as the Module, "Building" as the Screen and "Edit" as the Action:

if vartype(zpsecure) = "O" and not empty(occ_date) and val(zpsecure.bds) > 1
= messagebox("You cannot edit a finaled permit.",64,"Action Canceled")
buildscreen.isediting = .f.
endif

To use this option with ZP SQL the script needs a slightly altered first line:

if not empty(occ_date) and zpsecure.bds > 1
= messagebox("You cannot edit a finaled permit.",64,"Action Canceled")
buildscreen.isediting = .f.
endif


Preventing Violation Type Editing

The City of Whitehall wanted a way to prevent users from changing the Violation Type of existing violations. This was accomplished with two scripts. Both scripts use "Zoning" as the Module and "Violations" as the Screen. The first script uses "Edit" as the Action and it disables the Violation Type drop down box when editing:

vlscreen.zp_pageframe1.page1.cmbVio_type.enabled = .F.

Another script is need for the “Add” Action to make sure the drop-down box works when you are adding new violations:

vlscreen.zp_pageframe1.page1.cmbVio_type.enabled = .T.

Customizing The Application Group Labels

At the bottom of the Property Screen there is a radio button control we call the Application Group button that lets you switch from Zoning to Building to Housing to General to Custom permit databases. We had a customer request to change the label of "General" to "Site Plan". We did it with a script that used "Base" as the Module, "Property" as the Screen and "Screen" as the Action.

propscreen.app_option.option4.caption = “SitePlan”

Adding Items To Drop-Down Lists

At the City of Sandusky they wanted the option of “Court” to appear in the Billing Status drop-down box on the Rental Screen. Turns out you can use a script to add new options to the fixed list drop-down boxes in ZonePro. To accomplish this we used "Housing" as the Module, "Rental" as the Screen, and "Screen" as the Action.

rescreen.zp_pageframe1.page1.cmbBstatus.rowsource =;
rescreen.zp_pageframe1.page1.cmbBstatus.rowsource + ",Court"
rescreen.zp_pageframe1.page1.cmbBstatus.requery

3/03/2010

Changing the Default Document

By default the document screen for any database always has the top document option selected when the screen is launched. We had a customer who wanted to default to the Nuisance Letter option instead of the Violation Letter when the Violation Documents screen launched. To do this we created a script that used "Zoning" as the Module, "ViolateDoc" as the Screen, and "Screen" as the Action. The script is:

vdocs.doc_select.value = 4

Preventing Permit Number Alterations

A customer contacted me who was frustrated with employees who kept screwing up ZonePro's auto numbering feature for permit numbers by manually changing the suggested numbers to their own liking. This example prevents anyone from altering the permit numbers that ZonePro assigns to each new permit. This script uses "Zoning" as the Module, "Zoning" as the Screen, and "Screen" as the Action. The script is:

znscreen.zp_pageframe1.page1.txtcert.readonly = .T.

If you use a script like this and have the year as part of your permit numbering scheme, you'll have to disable the script at the start of each year in order to switchover to the new year.

Preventing Fee Editing

This script will prevent anyone from editing the fee amount once the fee has been paid. This example uses the Zoning database and keys in on the Date Paid field as the deciding factor.  I use "Zoning" as the Module, "Zoning" as the Screen, and "Edit" as the Action. The script is:

IF NOT EMPTY(date_paid)
znscreen.zp_pageframe1.page1.txtPer_fee.enabled = .F.
ELSE
znscreen.zp_pageframe1.page1.txtPer_fee.enabled = .T.
ENDIF

The second part of the script enables the Fee field again if you navigate to another record where the condition no longer holds true.

Changing Field Labels

One of the most popular uses for User Defined Scripts in ZonePro is for changing the screen labels in front of fields. In this example I'm selecting "Base" as the Module, "Property" as the Screen, and "Screen" as the Action and my script is:

propscreen.zp_pageframe1.page2.lblFlood.Caption = "School"

This will change the "Flood" label on the Extra tab of the Property screen to now read "School." To create a script like this you need to know several things that typically require our involvement. You need to know that the internal name for the Property screen is "propscreen" and that the Extra tab is referenced as "zp_pageframe1.page2". Once you know that you can theoretically change the label for any field on that tab. The trickier bit is knowing that the Flood label is called "lblFlood".  Usually the label for a field is the same as the internal field name prefixed by "lbl", but unfortunately we were not always consistent in our naming habits. A quick e-mail to us though will get you the answers to the screen and label names you want to change.

Using Picasa for On-line Photo Storage

This is a repeat topic I recently entered in the ZonePro Journal blog. The idea is to use an on-line service such as Picasa for storing photos and then using a script to launch the photos. In this scenario I envision a customer creating a separate on-line photo album for each property. The name you give to the album will then be part of the URL that is used to later launch that page of photos from the ZonePro property screen. Whatever you name the album, you need to store that name in a field in the Property database so you can access it via a script and launch the site. Alternatively you could name each album after the Property ID so you don't have to waste a field, but then the album name would be meaningless outside the context of ZonePro. In my example I created an album in Picasa and named it after the address: LOWELL584. I then stored the value "LOWELL584#" in the User3 field of the Property database. Note the # sign. Picasa adds that when it creates its URLs but it may not be necessary. The rest of the URL is always a constant for my Picasa account. Your account would be different, of course. I'm going to use the User Script button to launch the web page and create a script that checks to make sure a value exists in User3 before attempting to launch the web page. To set up the script I use "Base" for the Module, "Property" for the Screen, and "Left" for the Action:

IF NOT EMPTY(property.user3)
GoURL("http://picasaweb.google.com/zonepro32/"+property.user3)
ENDIF

Auto Number License Field in ZP32

In the previous post I showed how to auto number the License field in the Contractor screen with a script. That script was for ZP SQL. Some time earlier I had written a script for a customer who wanted to do the same thing in ZP 32. Their number scheme for the License field looks like this: "2010-0001". Again this script uses the User Script button and only works when you are editing. As before, this scripts uses "Contractor" as the Module, "Contractor" as the Screen, and "Left" as the Action. Here is the script:

IF CONTRACT.BROWSE_BTN.ENABLED = .F.
SELECT MAX(LICENSE) FROM CONTRACT INTO ARRAY MYLAST
MYPREFIX = STR(YEAR(DATE()),4)+"-"
MYNEWID = VAL(SUBSTR(MYLAST(1),6))+1
REPLACE LICENSE WITH MYPREFIX +
PADL(ALLTRIM(STR(MYNEWID)),4,"0")
CONTRACT.ZP_PAGEFRAME1.PAGE1.TXTLICENSE.REFRESH
ENDIF

Auto Numbering License in Contractor Screen

Yesterday I talked to a ZP SQL customer about automatically bumping up the number in the License field of the Contractor Screen in a fashion similar to Permit Number fields. I had already covered this topic for ZP 32 but the code is slightly different for ZP SQL. In this case the customer uses a numbering scheme like "C10-001" where 10 represents 2010. The script I created used the User Script button. While editing, clicking on the User Script button automatically fills in the next higher number in the License field. This scripts uses "Contractor" as the Module, "Contractor" as the Screen, and "Left" as the Action. Here is the script:

IF contscreen.isediting = .T.
myCommand = [SELECT MAX(license) AS maxnum FROM contract]
DoSqlCommand(myCommand,'myLicense')
myLast = VAL(RIGHT(TRIM(myLicense.maxnum),3))+1
myNext =  LEFT(myLicense.maxnum,4)+PADL(ALLTRIM(STR(MYLast)),3,"0")
USE IN IIF(USED('myLicense'),'myLicense',0)
SELECT contract
REPLACE license WITH myNext
contscreen.ZP_PAGEFRAME1.PAGE1.TXTLICENSE.REFRESH
ENDIF

Action Options for User Scripts

When you create user defined scripts in ZonePro one of the important setup options is identifying the "Action" that the script is connected to. Basically this determines when the script runs. There are three main Action options. If you use the Screen action then the script runs as the screen is launched. If you want something to happen before the screen is displayed, this is Action option you want. You can also attach scripts to several common control buttons such as the Add, Close, Delete, Edit or Save buttons. Attaching a script to those buttons means the script will run when that button is clicked.
The third script option is to attach the script to the User Script button (the open book icon). This button appears on almost every screen in ZonePro. This button provides three opportunities for scripts depending on whether you click on it with the Left, Right, or Middle mouse buttons.

How to Add User Scripts

All of the scripts on this site are user defined scripts. These scripts can be added to your ZonePro system by copying the script text from any post and pasting it into the User Defined Scripts screen in either ZP 32 or ZP SQL. The User Defined Script screen is accessed from the first tab in the Maintenance Options section of ZonePro. When you create a new script in the User Defined Script screen you first indicate which Module and Screen the script is assigned to and then the Action that the script follows. All of these selections are made via drop-down boxes at the top of the User Defined Script screen. Each post should tell you the Module, Screen, and Action that the script was written for. You would duplicate these choices in the User Defined Scripts screen, click on the "New" button, and then paste the script you copied into the main scroll box on the screen. Use the Windows hot-keys and to copy and paste. The last step is to simply hit the "Save Script" button and you have just added new functionality to your ZonePro system.

Yet Another Blog!

I know, I know. How many blogs does one company need? At least three, apparently. The reason for this blog is a little different. Over the past couple of years I have attempted to keep track of ZonePro user script examples in PDF documents on our web site. The problem there is that it is hard to find the one you are looking for when you know you've written a script but can't remember when. The advantage of the blog format is that you can use labels to help locate topics. This will make it much easier to search for a script. On the sidebar of this page you'll see a list of labels. You can click on any label of interest and see every entry that has a matching label assigned. If I do this right, the blog format should be a great way of cataloging user scripts.