duplicate record

A place for users and developers of the Xataface to discuss and receive support.

duplicate record

Postby cookie720 » Wed Jun 27, 2012 9:55 pm

I would like to be able to add a new record, with the previous record fields already in there (as though you just clicked on edit record) and just increment the ID by 1 and create a new record.
Is this possible?
cookie720
 
Posts: 69
Joined: Mon Jun 04, 2012 9:22 pm

Re: duplicate record

Postby Jean » Thu Jun 28, 2012 1:29 am

Yes it is possible when you select a record in the list and you click on the action copy_replace.

Jean
Jean
 
Posts: 259
Joined: Wed Nov 07, 2007 1:30 am
Location: Pau, France

Re: duplicate record

Postby cookie720 » Thu Jun 28, 2012 3:01 am

when i click copy set, i get "connection was reset" error.
cookie720
 
Posts: 69
Joined: Mon Jun 04, 2012 9:22 pm

Re: duplicate record

Postby cookie720 » Sun Jul 01, 2012 7:59 am

is there another way to do this? simply get the previous records data and chuck it into the fields...copy_replace function isnt working for me

do any of the trigger functions populate the fields during form entry? basically i want my "new record" to look as though i just clicked on edit (with the ID obviously incremented to a new record)

now im sure the "copy_replace" function does this exactly as I have described it, but it simply does not work. It says conection error when i click on it, Ive searched the problem and people have had it before.
cookie720
 
Posts: 69
Joined: Mon Jun 04, 2012 9:22 pm

Re: duplicate record

Postby shannah » Wed Jul 04, 2012 10:30 am

Check your error log to see why the connection was reset.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: duplicate record

Postby cookie720 » Fri Jul 13, 2012 8:28 pm

i dont know why the connection was reset, im not sure if this will fix my problem as other people have had this bug happen...there must be another way to get the field from the previous record and paste it into the input box , kind of like doing the default function/trigger?
Code: Select all
function Description__default(){
return the last updated record;

}

could someone help me with the steps/sql to do this?
cookie720
 
Posts: 69
Joined: Mon Jun 04, 2012 9:22 pm

Re: duplicate record

Postby shannah » Thu Jul 19, 2012 12:31 pm

If you have a date_posted field (or some field to track the time), then you can easily load the last inserted record either using df_get_record() or using a direct SQL query.

E.g. In your delegate class:
Code: Select all
private $lastInserted = null;
function getLastInserted(){
    if ( !isset($this->lastInserted) ){
        $this->lastInserted = df_get_record('mytable', array('-sort'=>'date_posted desc'));
    }
    return $this->lastInserted;
}


Then you could call this method from all of the language default methods:
Code: Select all
function Description__default(){
    $lastInserted = $this->getLastInserted();
    if ( $lastInserted ) return $lastInserted->val('Description');
}


Etc....

-Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: duplicate record

Postby cookie720 » Sun Jul 22, 2012 8:51 pm

working beautifully, but it gets the last updated record globally, not within the relative tables...So i need to somehow distinguish that its only for the relative tables

i dont know all the functions but its gotta be get related record in the df_get_record line or something

Code: Select all
private $lastInserted = null;
function getLastInserted(){
    if ( !isset($this->lastInserted) ){
        $this->lastInserted = df_get_record('status', array('-sort'=>'EditedLast DESC'));
    }
    return $this->lastInserted;
}


help!
and thanks shannah!
Last edited by cookie720 on Sun Jul 29, 2012 7:55 am, edited 1 time in total.
cookie720
 
Posts: 69
Joined: Mon Jun 04, 2012 9:22 pm

Re: duplicate record

Postby cookie720 » Sun Jul 29, 2012 7:54 am

any help greatly appreciated
cookie720
 
Posts: 69
Joined: Mon Jun 04, 2012 9:22 pm

Re: duplicate record

Postby shannah » Sun Jul 29, 2012 10:13 am

Sounds like your question pertains to the specific design of your database. Hence I can't comment. The last record you retrieve will be whatever record you tell it to retrieve in the df_get_record() call.
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Re: duplicate record

Postby cookie720 » Sun Jul 29, 2012 4:42 pm

i think it might be working like this:

Code: Select all
function getLastInserted(){
$app =& Dataface_Application::getInstance();
      $record =& $app->getRecord();
     // Grab FK value back to the parent record
     $key = $record->getValue( 'MatterID' );
    if ( !isset($this->lastInserted) ){
        $this->lastInserted = df_get_record('status', array('MatterID'=>$key));
    }
    return $this->lastInserted;
}


I took out the '-sort'=>'EditedLast DESC' because the delegate class already has this somewhere down the file
it seems to be working...is it correct to assume the __sql__ function is working for the getLastInserted function?

Code: Select all
function __sql__(){
return "SELECT * FROM `status` ORDER BY `StatusID` DESC";
}
cookie720
 
Posts: 69
Joined: Mon Jun 04, 2012 9:22 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 12 guests

Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved