Copy data from a form with events

Hi,

in a form I pre-fill some data over code in events. e.g. getting dates from other tables/records.
If I fill a new form the events work fine - but if I copy a form it does really copy everything without executing the onload events.

What do I have to do that the copy routine also executes the events so I have the correct data in a copied form?

Joe

I presume you really mean you are copying a record in a form, not a form?

The onLoad event in a form refers the to the app itself loading, e.g. if called from a menu, or redirected there by sc_redir() perhaps. Sounds like you need to use onLoadRecord which should get called if copying a record within the form. You may need to duplicate your code from onLoad into onLoadRecord so it runs whenver the app is loaded (onLoad), and again whenever a new record is created (onLoadRecord).

In fact, probably better to create a PHP method in your library with all the relevant pre-filling code, and then call it from both onLoad and onLoadRecord.

Thank you, but I use a single record form and onLoadRecord is not available there. Any ideas?

Joe

Really, for my single record forms I have an onLoadRecord event available? You sure you mean a form?

You could also use the sc_btn_copy macro in onLoad or onScriptInit to determine if the copy button use used and then repeat the code there.

if (sc_btn_copy) {
     sc_message("Record copied successfully!");
}

When I try to put some code into the OnLoadRecord event of a single record form I get this message

Unbenannt.JPG

Yep, my bad. Of course, you are right. Usually SC doesn’t show you stuff that’s not relevant, but given a form has multiple ways of working, that makes sense (I just jumped in and saw it was there - d’oh!)

The reason onLoad won’t work is still a valid point as that is triggered by the loading of the app itself. By copying a record the app is not reloaded, just a record is loaded (hence suggesting onRecord).

onNavigate may get triggered by the copy. Might want to try in there perhaps (not tested this). If you do (and it works) use the sc_btn_copy macro mentioned before to test, as I presume you only want the pre-fill to occur after a copy, not every time you move to a different record (assuming you have navigation options on)

I will try the button solution.
BTW - there is no macro ‘sc_message’ even though it’s described in the manual with the sc_btn macros :wink:

Joe

Yep - the docs are well known as being out of date in places - I just copied it to get the point across (think its sc_alert now btw)