Page 1 of 1
duplicate record
Posted:
Wed Jun 27, 2012 9:55 pm
by cookie720
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?
Re: duplicate record
Posted:
Thu Jun 28, 2012 1:29 am
by Jean
Yes it is possible when you select a record in the list and you click on the action copy_replace.
Jean
Re: duplicate record
Posted:
Thu Jun 28, 2012 3:01 am
by cookie720
when i click copy set, i get "connection was reset" error.
Re: duplicate record
Posted:
Sun Jul 01, 2012 7:59 am
by cookie720
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.
Re: duplicate record
Posted:
Wed Jul 04, 2012 10:30 am
by shannah
Check your error log to see why the connection was reset.
Re: duplicate record
Posted:
Fri Jul 13, 2012 8:28 pm
by cookie720
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?
Re: duplicate record
Posted:
Thu Jul 19, 2012 12:31 pm
by shannah
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
Re: duplicate record
Posted:
Sun Jul 22, 2012 8:51 pm
by cookie720
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!
Re: duplicate record
Posted:
Sun Jul 29, 2012 7:54 am
by cookie720
any help greatly appreciated
Re: duplicate record
Posted:
Sun Jul 29, 2012 10:13 am
by shannah
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.
Re: duplicate record
Posted:
Sun Jul 29, 2012 4:42 pm
by cookie720
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";
}