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.