What I would like to be able to do is have one grid shown on the top of the screen loading original source data from Table A. Then have a second Table B as a grid shown below that so that if a user clicks the clone record button on Table A it is inserted to Table B for them to make any changes to. How would I go about doing this and is it possible to make Table A non editable yet still have the Clone option to copy to Table B?
Thanks in Advance!
You can use on_clone event handler and write your own code to insert in other table.
Thank you. That works perfect!
The only other things I can’t quite seem to get working on clone handler are to set the Created date in the table it’s inserted to along with Created_By as the persons name who clicked the clone button. The persons name would be a preset PHP variable pulled from their profile. The on clone event insert query I did change to a plain SQL Select/Insert because I didn’t want to insert all of the “Cloned” column values, just a subset.
So for example the SQL I changed it to be like this.
$sql = “INSERT INTO Books (Title, ISBN, Author, Published, Publisher, Category, Type) SELECT Title, ISBN, Author, Published, Publisher, Category, Type) FROM Inventory WHERE id = $src_id”;
Id like to have Created set to current date the clone button was pressed and Created_By set to $Created_By
Is there an easy way to do this either within that on_clone event handler or immediately after the insert is made?
Thanks!
You can use similar query with bold modification.
$sql = “INSERT INTO Books (Title, ISBN, Author, Published, Publisher, Category, Type, Created_date, Created_by) SELECT Title, ISBN, Author, Published, Publisher, Category, Type, NOW() as Created_date, ‘$Created_By’ as Created_By FROM Inventory WHERE id = $src_id”;
This is an SQL Server table I am trying to get this to work for. When I put the variable name inside quotations and refresh the grid nothing is displayed but a blank page. If I put the variable between single quotes the grid loads but the variable value is not passed to the insert query. It’s just an empty value. I’m sure it’s something simple I am doing wrong here.
Using single quote should work. Make sure the variable $Created_By contains value. You can check by hardcoding it. e.g.
$Created_By = “test”;
$sql = “INSERT INTO Books (Title, ISBN, Author, Published, Publisher, Category, Type, Created_date, Created_by) SELECT Title, ISBN, Author, Published, Publisher, Category, Type, NOW() as Created_date, ‘$Created_By’ as Created_By FROM Inventory WHERE id = $src_id”;