Page 1 of 1

duplicate a record

PostPosted: Thu Feb 25, 2010 4:17 pm
by gsilvis
I want to be able to duplicate one record of a table (not a whole set). One way would be a button or action from the Edit screen, using the field data displayed (ie, the record I want to duplicate would be displayed). The key for the database is not shown in the editable fields. One of the fields is a blob, the rest text.

Suggestions on how I could do this?

Many thanks
George

Re: duplicate a record

PostPosted: Thu Feb 25, 2010 5:41 pm
by shannah
The easiest thing would be to just use the copy set action, but on a single record.
index.php?-action=copy_replace&--copy=1&myid=10

This would give you the copy form for only the record with myid=10.

Re: duplicate a record

PostPosted: Thu Feb 25, 2010 9:03 pm
by gsilvis
shannah wrote:The easiest thing would be to just use the copy set action, but on a single record.
index.php?-action=copy_replace&--copy=1&myid=10

This would give you the copy form for only the record with myid=10.


So, if my key field is named "key" then I would need to know the value of the field for the current record. Is that at hand?

Thanks again,
George

Re: duplicate a record

PostPosted: Fri Feb 26, 2010 8:28 am
by shannah
Code: Select all
$currentRecord = Dataface_Application::getInstance()->getRecord();
$keyval = $currentRecord->val('key');

Re: duplicate a record

PostPosted: Sun Feb 28, 2010 8:51 am
by gsilvis
Ok, got it working. To the cards.php file I added the following code:

Code: Select all
        // Duplicate Record function
        function block__after_edit_record_form() {
              $currentRecord = Dataface_Application::getInstance()->getRecord();
              $keyval = $currentRecord->val('key');                   
              echo("<a href=\"http://www.gasilvis.com/Eggen/index.php?-action=copy_replace&--copy=1&key=$keyval\">Duplicate this record </a>");
        }


This gives me a clickable point at the bottom of the edit form that will duplicate the current record.

A side affect of using the action-copy_replace is that the current set is redefined at completion to a set with one record, the new record. It would be nicer to still be in the edit page with the current set increased by the copied record.

Thanks again for the help,
George