1/27/2011

Copy and Pasting Fields Between Records (ZP 32 or ZP SQL)

A customer using the Rental Screen wanted to be able to copy information from the existing rental record whenever they added a new one. There is a built-in carry-over option in the Rental Screen if you right-click on the Add button, but that option does not copy all the fields this customer needed. I devised the following script as a way to copy and paste multiple fields at a time between any two records in the same database. This script uses "Housing" for the Module, "Rental" for the Screen and "Left" for the Action:

myaction = inputbox("Enter C to Copy or P to Paste")
if lower(myaction) = "c"
javascript:void(0)
wait window "copying fields..." nowait
public mydata
mydata = createobject("empty")
addproperty(mydata,"user1",rental.user1)
addproperty(mydata,"user2",rental.user2)
addproperty(mydata,"user3",rental.user3)
addproperty(mydata,"user6",rental.user6)
addproperty(mydata,"notes1",rental.notes1)
endif
if lower(myaction) = "p"
wait window "pasting fields..." nowait
if vartype(mydata) = "o"
rescreen.isediting = .t.
gather name mydata memo
release mydata
endif
rescreen.refresh
endif

NOTES
- This script crams both the Copy and Paste actions into one button (the left click Script button) with a prompt to decide which action to take. You could also easily split this into two scripts and put the Copy action in the left click and the Paste action in the right click and drop the prompt code.
- You can revise a script like this to work with any of the ZP databases and with any number of fields.
- Note that the Paste option puts you into Edit Mode, which means you can Cancel the Edit to negate the paste.

1/25/2011

Adding Alerts After Completed Inspections

Today I had a customer who wanted to add an alert message to their system after certain types of inspections were completed. This script checks after each Save to see if the Last Inspect date is filled and if the inspection item is a "Foundation". If so it displays a message. This script uses "Building" for the Module, "Buildinsp" for the Screen, and "Save" for the Action:

 if  not empty(last_insp) and detail = "FOUNDATION"
= messagebox("Check for As Built",64,"Alert")
endif

1/14/2011

Who Scheduled That?

Had a customer ask if there was a way they could keep track of who scheduled a particular Building Inspection and when. I devised a script that checks to see when the Next Inspection date changes and then replaces the Last Time field with the current users initials and the month and day. This script uses "Building" for the Module, "Buildinsp" for the Screen, and "Save" for the Action:

if insp_date <> oldval("insp_date")
replace last_time with trim(zonepro.owner)+left(dtoc(date()),5)
endif

NOTES
- It is the OLDVAL( ) function that checks to see if the Next Inspection date field has changed during editing.
- This script is not of any use in ZP 32 if you are not using Security.
- For ZP SQL you would change "zonepro.owner" to "zpsecure.ownint".
- There are only a handful of fields available to stick this info into. I chose Last Time because this field should be blank when you are scheduling a new inspection.

1/12/2011

Archiving Fields in the Notes

I have a customer who wants to archive old data before they edit and change the value of certain fields. You can easily automate the archiving of various fields into one of the Notes fields by using a script. The example I'm using is archiving the Zoning District and the Existing Use fields in the Property Screen into the Notes1 field. The script copies the fields into the Notes when you click on the Script button while editing a Property record. This script uses "Base" for the Module, "Property" for the Screen, and "Left" for the Action:

if propscreen.isediting = .T.
replace notes1 with iif(empty(notes1),"",alltrim(notes1) +chr(13)+chr(13));
+ "ZONING ARCHIVED: "+dtoc(date()) + chr(13)+;
"Old Zoning: " + alltrim(zoning);
+"  Use: " + alltrim(exist_use)
propscreen.refresh
endif

In ZP 32 the "notes1" field should be referred to as "notes".

1/06/2011

A Variation On Locking the Notes Field

There is an option in the Global Options screen that lets you lock the Note2 field is various screens so that no one can alter any text that has been moved into that field using the Append Notes button. Today I worked out a way that you can imitate that same effect on either the Notes1 or Notes2 field with the added benefit of a security level check. With this script, anyone with a security level greater than 1 cannot directly edit the Building Notes1 field. They can still add to the field however by typing into the Notes2 field and then using the Append Notes button to add that text to the existing text in Notes1. Note that the script must also disable the other Append Notes button. This script uses "Building" for the Module, "Building" for the Screen, and "Edit" for the Action:

if vartype(zpsecure) = "O" and val(zpsecure.bds) > 1
buildscreen.zp_pageframe1.page4.edtNotes1.enabled=.F.
buildscreen.zp_pageframe1.page4.notes_buttons1.move1_btn.enabled=.F.
endif

You may want to clean things up by adding another script to the "Save" action that re-enables the text to make it more readable.

For ZP SQL the script would be:

if zpsecure.bds > 1
buildscreen.zp_pageframe1.page3.edtNotes1.enabled=.F.
buildscreen.zp_pageframe1.page3.notes_buttons1.move1_btn.enabled=.F.
endif

You could also change the script to make access dependent on a user's Security Initials so that only one person had access. Do this by changing the first line to:

if zpsecure.ownerinit <> "ZPD"